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:
Gentlemen, START YOUR TEXTEDITORS
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.
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
I'd do something but I'm busy with other things. We shall see.
"you must be willing to give your code out to the public domain."
what
You post anything here it becomes property of the internet... sif you have a say on the matter.
then why saying it
Is perl::sdl okay?
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.
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.
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.
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.
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.
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.
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.
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.
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.
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)
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.
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!
Cygwin has its own annoying DLLs. Mingw is the way to go.
Dev-C++ + mingw for teh win.
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);
?>
>>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.
oops, that should've been ls -l file
and 1314. where [Del] go?
Can we have an example installation somewhere to see what it actually outputs?
>>24: Don't mind at all. Go ahead.
ls -l
... That's too easy. Bah, what a fool am I. :P
hmm... my tripcode database script is 4066 bytes, plus wakautils.pl... would that count under the "Common standard libraries" thing?
>>29
Hey, could you email me at h-cube @ x-maru org regarding this.
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);
?>