5 ms·
Interesting C code
- jseban 15y agoInteresting indeed. But weird that he uses obfuscated code when doing a piece of explaining how it's done. Or do people actually write for loops like those? :P
- LukeShu 15y agoThis is basically the a C equivalent of a JAPH. A JAPH is a usually short bit of perl code that prints "Just Another Perl Hacker", but it isn't obvious that that's what it does. Trying to figure out how it works without cheating is part of the fun.
- sofuture 15y agoa.{~(/:a+c=:_29 14 _60 12 8 0 _2 5 3 2 11 6 14 _1 8 13){+/\a=:(#.1,5$0),1,(#.1,6$0),0,(2$2),(#:20),~(3*1 1r3,|.i.3)
- tintin 15y ago"in six lines of C" I'm not impressed. It could be done in 1 line of C when he left out the line-breaks. I don't think obfuscated code is interesting. It's unreadable. And therefore it's hard to learn something from it. But it's nice he is explaining the code. Now that is interesting!
- Kapelson 15y agoI treat obfuscated code as a kind of puzzle. "Given a crazy string of seemingly random semicolons and numbers, can you discover what it does and how it works?" It's like a magic eye puzzle for a programmer.
- nadam 15y agoObfuscation alone is not interesting, but 'code compression' (to achieve something using as few characters as possible) is a very interesting puzzle for the brain I think.
- pavel_lishin 15y agoIt's called "code golf", and from what I can tell, perl is the undisputed king of golfing languages. Someone ought to make a quiz page - "is this perl golf, or a cat walking on a keyboard".
- apgwoz 15y ago,[.,] is /bin/cat in brainfuck. Though, brainfuck fails miserably at most golfing challenges.
- icebraining 15y ago,[.,] doesn't actually concatenate files, though. Personally, I think that using golf handicapped languages is the only way to keep it interesting. If you can choose the language, it gets too easy. One could even implement 'cat' as a single character, provided his language of choice.
- rcfox 15y agoThe code isn't obfuscated; it's golfed. (http://codegolf.com/ http://codegolf.com/) I assume the line-breaks are to allow the code to fit within 80 columns to display on most standard terminals. If you look closely, they occur at places you wouldn't expect them to. I'm guessing they were placed by cat and not the author.
- alecbenzer 15y ago"It could be done in 1 line of C when he left out the line-breaks." Yeah, exactly. It's incredibly silly when people "count" lines of code like this. If you want to talk about lines of code in any kind of practical way, the code you're referring to really needs to be at least somewhat sanely formatted according to the conventions of whatever language you're in. Otherwise, any given sample of code can be in {1,2,3,...,# of characters in program} lines of code. You should just count characters (which is the more appropriate thing to do when you're trying to write a compressed program anyway). A metric of lines of code = ceil(characters/80) is weird because a) it's relatively arbitrary (in that it has nothing to do with languages but with the conventions of terminals), and b) it goes against the more common understanding of "lines of code". /rant I think compressed (edit: golfed - new word of the day :) code in general is pretty cool, though.
- a1k0n 15y agoI could have said "in 454 characters of C" but that wouldn't have been as linkbaity. Thanks for clicking! Yes, the aim was compression (golfing), not obfuscation. Compression of silly ASCII things has been sort of a hobby of mine for a while and I intend to blog about that in particular. Another little compressed snippet is my "email signature" at the bottom of my site root. Try clicking on it.
- chamakits 15y agoBoth of these (the signature, and the post) are amazing! ....jealous
- huhtenberg 15y agohttp://a1k0n.net/2006/09/15/obfuscated-c-donut.html http://a1k0n.net/2006/09/15/obfuscated-c-donut.html Jesus Christ. I love you, dude. Your site must have the highest awesomeness-per-bit ratio on the Internet :)
- a1k0n 15y agoThanks. :) I'm most proud of my IOCCC 2006 winner (the IOCCC organizers announced the winners, but not the actual entries, then disappeared from the planet): http://a1k0n.net/2006/09/20/obfuscated-c-donut-2.html http://a1k0n.net/2006/09/20/obfuscated-c-donut-2.html
- thehelix112 15y agoAgreed.
- xedarius 15y ago'warnings which real programmers ignore' ... That tells me pretty much all I needed to know about that article.
- Bogdanp 15y agoI can't speak for the author, but I'm pretty sure that was a joke.
- a3_nm 15y agoIn case you're wondering... $ gcc -o yanim yanim.c -lm yanim.c:1:1: warning: data definition has no type or storage class [enabled by default] yanim.c: In function ‘main’: yanim.c:5:24: warning: incompatible implicit declaration of built-in function ‘cos’ [enabled by default] yanim.c:5:33: warning: incompatible implicit declaration of built-in function ‘sin’ [enabled by default]
- Martijn 15y agoWarnings are to be expected if your goal is to make your program as short as possible.
- sirk390 15y agoWow, impressive. And I love your humour about warnings :)
- mrpollo 15y agothe javascript port is awesome too http://jsfiddle.net/mrpollo/jeNau/ http://jsfiddle.net/mrpollo/jeNau/ tho i cant make it run yet on jsfiddle
- petercooper 15y agoCopied and pasted that into JSBin and it worked like a champ: http://jsbin.com/osihah/edit http://jsbin.com/osihah/edit
- mrpollo 15y agoAwesome!, thanks, it runs great
- deleted 15y ago[deleted]
- aralib 15y agoNow I really want to learn ray tracing (and computer graphics in general).
- johnx123-up 15y agoMy favorite is world map code by Brian Westley http://www.ioccc.org/1992/westley.hint http://www.ioccc.org/1992/westley.hint main(l ,a,n,d)char**a;{ for(d=atoi(a[1])/10*80- atoi(a[2])/5-596;n="@NKA\ CLCCGZAAQBEAADAFaISADJABBA^\ SNLGAQABDAXIMBAACTBATAHDBAN\ ZcEMMCCCCAAhEIJFAEAAABAfHJE\ TBdFLDAANEfDNBPHdBcBBBEA_AL\ H E L L O, W O R L D! " [l++-3];)for(;n-->64;) putchar(!d+++33^ l&1);} BTW, how to convert C to JavaScript?
- vegai 15y agoI sometimes wonder if code golfing has the risk that some junior developers might confuse it as good code.