Coding Challenge #2! (115)

1 Name: Yaranaika Daddy!K./5Izeg0I 05/01/08(Sat)11:21 ID:Heaven This thread was merged from the former /code/ board. You can view the archive here.

Alright people who know how to tell there computer what to do and how to get there... I bring you a challenge from the interweb.

THE 4K CODE CHALLENGE

Objective: To create the most productive/useful code that as source code is no larger than 4 kilobytes (4096 bytes). There is no restrictions as to what your code does, or what language it is used in.

Rules:

  • The code must be yours, and you must be willing to give your code out to the public domain.
  • You must state EXACTLY what your code does. If it is malicious you must state what it does/exploit.
  • There is no restriction on what language, however markup languages are not allowed. Javascript/VBScript are, and any HTML required to perform the task is not counted towards the byte tally however objects calling to Javascript/VBScript do.
  • Common standard libraries (.h files, javabeans, perl modules etc) are allowed and dont count towards the byte tally.
  • You can use as many seperate files in your source code as you wish.
  • If you code requires to be compiled to run, it must be able to compile without a problem. For C and other languages that require a makefile, these will not go towards the byte tally.
  • Any other data in the form of databases, information etc that isn't a part of the code also does not count towards the byte tally.
  • If your program requires parameters to begin, you must state what they do.

Gentlemen, START YOUR TEXTEDITORS

2 Name: MAD-Leser!r4YvKJpWUc 05/01/10(Mon)21:27 ID:nGxHCmQO

this thread seems dead or something, so i take it that either nobody's hacking up some code or everybody's still at it.confirm/deny :O?
as for me, i'm about 3/4 done i think.. and i still have plenty of bytes to waste code and long strings/variable names on. coders using a language the kind of perl, ruby or python have a huge advantage when only filesize and productivity matter... so this challenge is somewhat unfair to, say, the c/c++/java/malbolge crowd imo.

3 Name: dmpk2k!hinhT6kz2E 05/01/10(Mon)22:58 ID:U/4Lko+c

The challenge is a great one, but I don't think people have that much time. It's also amazingly open-ended.

BTW, here's my recipe for guaranteed success:

Make a tiny makefile that takes filenames, inserts them into a file, and compiles the result. Put all the code in filenames, leave the file empty, and on some filesystems you could fit an entire kernel tree in 0 bytes.

All perfectly within the rules too! Whee! >;D

4 Name: !WAHa.06x36 05/01/11(Tue)02:22 ID:/+PXKXxy

I'd do something but I'm busy with other things. We shall see.

5 Name: Sling!myL1/SLing 05/01/11(Tue)05:10 ID:dLpnwG9j

"you must be willing to give your code out to the public domain."
what

6 Name: !#usr/bin/anon 05/01/11(Tue)07:20 ID:Heaven

>>5

You post anything here it becomes property of the internet... sif you have a say on the matter.

7 Name: Sling!myL1/SLing 05/01/11(Tue)13:34 ID:dLpnwG9j

then why saying it

8 Name: hk0!0khonVgaHI 05/01/11(Tue)19:50 ID:vsz+JQjs

Is perl::sdl okay?

9 Name: !WAHa.06x36 05/01/11(Tue)20:04 ID:lgKw1nXR

I was thinking of using SDL from Perl too, but it seems to kind of suck. Just the base SDL library, with nothing much in the way of graphics drawing except blitting. Boring.

10 Name: hk0!0khonVgaHI 05/01/11(Tue)23:24 ID:rKF21LnW

well, don't you get an event loop, timers, stuff like that, and audio?

I think it'd be cool to whip up a little keyboard-based realtime synth with some sort of cheezy visual feedback.

11 Name: dmpk2k!hinhT6kz2E 05/01/12(Wed)04:56 ID:Uw9t6Zjq

You could always use Allegro. Oft overlooked, but both mature and stable. Perfect for 2D gaming with things like blitting, timers, audio, midi, controls, yadda, yadda. I have no idea if someone has cooked up a perl module that interfaces with it though.

Allegro is a lot older than SDL (and better maintained). Perhaps they were looking for something more lightweight, but I think Allegro should have become de facto, not SDL.

12 Name: !WAHa.06x36 05/01/12(Wed)13:03 ID:2WCeiP4k

I've written several (unfinished, of course) games in Allegro, and it is a joy to work with, but it's really not very good at interfacing with the host OS. SDL wins there, but not by much. SDL is also more widely supported.

13 Name: hk0!0khonVgaHI 05/01/14(Fri)23:23 ID:WOOBWhQ6

Allegro was cool back when I was playing with DJGPP and DOS extenders. Nowadays it reaches too much and carries around too much useless cruft.
SDL seems leaner and meaner, leaving other details to other libraries.

14 Name: !WAHa.06x36 05/01/15(Sat)00:01 ID:lqDg5myq

However, I absolutely despise the "leave other details to other libraries" mindset. It makes for a horrid mess of libraries to get and install to compile code, or even worse, to install just to run the software.

15 Name: dmpk2k!hinhT6kz2E 05/01/15(Sat)08:55 ID:KX4X061+

I have to side with WAHa on this. While I well understand the reasons for libraries, it still annoys me no end the number of amazingly rare libraries that are used by single programs. There has to be a balance between code sharing and dependency.

IMHO SDL doesn't suffer from excessive libraries, but for a developer working with cross-platform code Allegro is a saner choice.

16 Name: !WAHa.06x36 05/01/15(Sat)12:56 ID:lqDg5myq

SDL is nice for doing 3D work, because the only other library you need then is OpenGL, and maybe some image loading code. But for 2D code, I just can't be arsed to track down and install a zillion different libraries (who even more annoyingly often don't like statically but instead use a zillion DLLs) just to get some sprites and graphics going.

17 Name: dmpk2k!hinhT6kz2E 05/01/15(Sat)15:26 ID:+LUicS67

There's SDL. There's OpenGL. Now here's a question I've been wondering for a while: what's the deal with OpenAL?

AFAIK it's pretty rare, so I doubt anyone here has twiddled with it, but it'd be interesting to know what the hearsay about it is.

18 Name: Z!XUZ3/z7o3k 05/01/16(Sun)19:05 ID:7bS68WGM

Well I was bored this afternoon and tired of studying for exams so here's my "entry", I guess.

Horribly ugly C++ code using SDL and OpenGL to display PQ-torus-knots. It defaults to a 1024x768 window so if that doesn't work out for you, you need to recompile :)

Keyboard controls: space for next knot, w to toggle wireframe, o to toggle the oscillating effect, esc to exit.

Source is 4090 bytes, using unix line endings and still plenty of readability (newlines, tabs) - I suppse I could take all those out and hit about 3800-ish but why bother.

http://ufoz.underclocked.com/waka4k.cpp
^^^ for the source
http://ufoz.underclocked.com/waka4k.zip
^^^ for a windows exe (I think it may require msvcp71.dll, I was lazy to include it in the download but you can get it from dllfiles.com or something... sdl.dll is included, or I guess you guys can recompile from the source, not_a_virus.exe and all that)

19 Name: !WAHa.06x36 05/01/16(Sun)19:54 ID:AwTGBp/L

Pretty nice! However:

> I think it may require msvcp71.dll

Get a real compiler! http://www.mingw.org/

http://wakaba.c3.cx/stuff/z-waka4k.zip doesn't need any annyoing DLLs.

20 Name: Z!XUZ3/z7o3k 05/01/16(Sun)20:19 ID:+9BzT4rV

Meh, I do have cygwin installed, but I only tested it to make sure it compiles with g++ :) Way too lazy to get my libs working.

Thanks for recompiling!

21 Name: !WAHa.06x36 05/01/16(Sun)20:53 ID:AwTGBp/L

Cygwin has its own annoying DLLs. Mingw is the way to go.

22 Name: dmpk2k!hinhT6kz2E 05/01/16(Sun)22:40 ID:cEBj5NTs

Dev-C++ + mingw for teh win.

23 Name: Albright!LC/IWhc3yc 05/01/18(Tue)09:54 ID:z4JMghGA

A PHP-powered text obfuscator, for OCR resistance. Originally written for a project I never released, I've recently tweaked it for a project I'm working on now which I'll also probably never release. Probably needs some tweaking; it obfuscates a little too well at times...

It weighs in at under 1.5K. It could be made smaller by using one-character variable names and reducing whitespace and such, but I'm actually using this code in a project, so it has to be legible...

Incidentally, anyone know the UNIX command to get the actual size of a file (not the whatchamacallit du -h provides)? (lol "duh" lol)

<?php
$code="Text to obfuscate";
$clen=strlen($code);
if (mt_rand(0,1)==0) {
$back=mt_rand(0,50);
$dark=true;
}
else {
$back=mt_rand(205,255);
$dark=false;
}
$right=mt_rand(-1,4);
for ($i=0; $i<$clen; $i++) {
$pos[$i]=mt_rand($right, $right+4);
$fonts[$i]=mt_rand(4,5);
$right=$pos[$i]+imagefontwidth($fonts[$i])+2;
}
$theimg=imagecreate($right, 16);
imagecolorallocate($theimg,$back,$back,$back);
$lines=$clen*5;
for ($i=0; $i<$lines; $i++) {
if ($dark==true) {
$clr=mt_rand(0,127);
}
else {
$clr=mt_rand(128,255);
}
$clr=imagecolorallocate($theimg,$clr,$clr,$clr);
imageline($theimg,mt_rand(0,$right),0,mt_rand(0,$right),16,$clr);
}
for ($i=0; $i<$clen; $i++) {
if ($dark==true) {
$clr=mt_rand(191,255);
}
else {
$clr=mt_rand(0,63);
}
$clr=imagecolorallocate($theimg,$clr,$clr,$clr);
$horiz=mt_rand(-1,16-imagefontheight($fonts[$i]));
imagestring($theimg, $fonts[$i], $pos[$i], $horiz, $code{$i}, $clr);
for ($j=0; $j<($fonts[$i]*2); $j++) {
imagesetpixel($theimg, mt_rand($pos[$i],$pos[$i]+imagefontwidth($fonts[$i])),mt_rand($horiz, $horiz+imagefontheight($fonts[$i])), $clr);
}
}

header("Content-type: image/png");
imagepng($theimg);
?>

24 Name: h3!hcube5iNfc 05/01/18(Tue)12:02 ID:edWZ6xgM

>>23
Nice. Mind if I swipe it for ochiba?

> Incidentally, anyone know the UNIX command to get the actual size of a file

ls file
wc -m file

Comes in at 1341 with tabs expanded.

25 Name: h3!hcube5iNfc 05/01/18(Tue)12:03 ID:edWZ6xgM

oops, that should've been ls -l file

26 Name: h3!hcube5iNfc 05/01/18(Tue)12:04 ID:edWZ6xgM

and 1314. where [Del] go?

27 Name: !WAHa.06x36 05/01/18(Tue)12:45 ID:XBXp5bEx

>>23

Can we have an example installation somewhere to see what it actually outputs?

28 Name: h3!hcube5iNfc 05/01/18(Tue)17:11 ID:FQo9t53p

29 Name: Albright!LC/IWhc3yc 05/01/18(Tue)19:13 ID:ybyrx/dj

>>24: Don't mind at all. Go ahead.

ls -l... That's too easy. Bah, what a fool am I. :P

30 Name: hotaru!hoTarufiRE!!Cizp3pu2 05/01/18(Tue)22:24 ID:rEXJ8Qc2

hmm... my tripcode database script is 4066 bytes, plus wakautils.pl... would that count under the "Common standard libraries" thing?

31 Name: h3!hcube5iNfc 05/01/19(Wed)02:32 ID:FQo9t53p

>>29
Hey, could you email me at h-cube @ x-maru org regarding this.

32 Name: Albright!LC/IWhc3yc 05/01/19(Wed)21:21 ID:fAEpFZRB

With text rotation. Wheee! A flaw of this, however, is that it becomes impossible to guess the vertical height of the resultant image... 1989 bytes. http://www.anre.org/crap/obfu.php

<?php
$code="Text to obfuscate";
$clen=strlen($code);

for ($i=$clen; $i<3; $i++) {
$code="0".$code;
$clen++;
}
if (mt_rand(0,1)==0) {
$back=mt_rand(0,50);
$dark=true;
}
else {
$back=mt_rand(205,255);
$dark=false;
}

$right=mt_rand(-1,4);
for ($i=0; $i<$clen; $i++) {
$pos[$i]=mt_rand($right, $right+4);
$fonts[$i]=mt_rand(4,5);
$right=$pos[$i]+imagefontwidth($fonts[$i])+2;
}
$textimg=imagecreatetruecolor($right, 16);
if ($dark) {
$xback=imagecolorallocate($textimg,$back,$back,$back);
}
else {
$xback=imagecolorallocate($textimg,$back,$back,$back);
}
imagefill($textimg,0,0,$xback);

for ($i=0; $i<$clen; $i++) {
if ($dark==true) {
$clr=mt_rand(191,255);
}
else {
$clr=mt_rand(0,63);
}
$clr=imagecolorallocate($textimg,$clr,$clr,$clr);
$horiz=mt_rand(-1,16-imagefontheight($fonts[$i]));
imagestring($textimg, $fonts[$i], $pos[$i], $horiz, $code{$i}, $clr);
for ($j=0; $j<($fonts[$i]*2); $j++) {
imagesetpixel($textimg, mt_rand($pos[$i],$pos[$i]+imagefontwidth($fonts[$i])),mt_rand($horiz, $horiz+imagefontheight($fonts[$i])), $clr);
}
}

for ($rot=mt_rand(-10,10);$rot==0;$rot=mt_rand(-10,10)) {
}
$textimg=imagerotate($textimg,$rot,$xback);
//Rotating an image with transparency breaks GD or something, so we have to apply transparency after rotation. Gay.
imagecolortransparent($textimg,$xback);

$thew=imagesx($textimg);
$theh=imagesy($textimg);
$strimg=imagecreate($thew,$theh);
imagecolorallocate($strimg,$back,$back,$back);
$lines=$clen*5;
for ($i=0; $i<$lines; $i++) {
if ($dark==true) {
$clr=mt_rand(0,127);
}
else {
$clr=mt_rand(128,255);
}
$clr=imagecolorallocate($strimg,$clr,$clr,$clr);
imageline($strimg,mt_rand(0,$thew),0,mt_rand(0,$thew),$theh,$clr);
}

imagecopymerge($strimg,$textimg,0,0,0,0,$thew,$theh,100);
header("Content-type: image/png");
imagepng($strimg);
?>
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: