Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I always love these things. "X in Y lines of $language!"

Then you look at it and realize that a "line" is actually 20 different statements minified.

I found jquery implemented in a single line![1]

[1] https://jquery.com/download/



The lines don't seem to be over 80 chars long. It's code golf so it's still going to be hard to read but the 80 char lines are acceptable in most code bases.


"Lines of C" is an arbitrary and relatively meaningless metric. Even number of characters would have more meaning and perhaps be more interesting than number of 'lines'. Unless you define a "line" as 80 characters (in which case you really have a rough estimation of character count).

Nonetheless, these things are fun and often novel, both in what they accomplish and how they accomplish it. I like looking at them (not always reading them) for many of the same reasons I like looking at brainfuck or perl code. Plus, you know, compression. ;)


Come on, were you really expecting that animation to be done in, like, 6 statements? Even once you understand the current of compression ratios minification of c code can achieve, this is still impressive. I bet the 'uncompressed' version of this code would still be interesting. Actually - here's where I kinda agree with you - it would probably be much more interesting, since we'd be able to understand it more readily.


I transformed the code into something sort of readable, although still somewhat difficult to understand:

https://gist.github.com/a1k0n/15f6cc2fc9428d6fd197


"[Update 10/21/2015: Changed the title from "six lines of C" to "462 bytes of C" to avoid endless arguments about what constitutes a line of C code.]"


This kind of game was common in BBC Basic, way back in the 80s and 90s. It was limited to 255-ish tokens per line. (Excitingly, the keyboard buffer was 255 characters, but each keyword was tokenised to a single byte. Which meant that with trickery it was possible to get lines of Basic longer than it was actually possible to edit.)

At least one of the computer magazines of the day had a regular column of one-line BBC Basic programs sent in by readers. There were some quite good games.

Alas, I suspect that most of these have been lost to history, but here's a one-line Tetris:

        0d=d:IFdVDUd:a=POINT(32*POS,31-VPOS<<5):RETURNELSEMODE9:GCOL-9:CLG:O
    FF:d=9:REPEATVDU30:REPEATGOSUBFALSE:IFPOS=28VDUPOS,15,VPOS,24;11,26:IF0E
    LSEIFa=0PRINT:UNTIL0ELSEUNTILVPOS=25:v=ABSRNDMOD7:i=0:VDU4895;3:REPEATm=
    9-INKEY6MOD3:FORr=TRUETO1:t=rANDSGNt:IFt=rCOLOURv-15:VDUrEORm:i+=m=7AND9
    -6*r:IF0ELSEFORn=0TO11:d=n/3OR2EORd:GOSUBFALSE:IF1<<(n+i)MOD12AND975AND&
    C2590EC/8^vVDU2080*ABSr;:t+=a:IF0ELSENEXT,:VDU20:UNTILt*LOGm:UNTILVPOS=3
http://survex.com/~olly/rheolism/dsm_rheolism/


Even if you run a formatter over the source and rename the variables to some longer names, these tiny programs are still algorithmically impressive. Otherwise they'd be nearly trivial to generate from bigger ones by running minifiers on them.


Many where like minimally functioning PoC. When I thought about raytracing I always assumed large code base. Watching the bare principle in a snippet is pretty awesome.


Sometimes it's more than lexical minification though, you also learn a bit about the grammar and how to express something in fewer bits. Even tiny design tricks, like encoding binary as chars to express data.


Yes, I don't see how this isn't

> Yahoo Logo ASCII Animation in one line of C (2011)

What's the difference between six lines of C and one line of C?


400 characters? Assuming one line is 80 characters max.


Yeah, I think you have to count a semi-colon as a "line of C" for this to be meaningful. It's still awesome none-the-less.


    for(i=0;i<4;i++)
This is three lines?


Actually there are two types of ";", expression-separator (the one you mentioned) and statement-separator (the one parent meant)

The problem with using those for code metrics is that many systems don't require separators, like `if`, `for` and friends


FWIW, most of this code is actually contained inside for loop expressions, since you can chain them together with commas and get away without using any braces. Once that's done it's hard to even count "lines".


Why not? It expands to 2 statements and a statement-expression: int i = 0; while (i < 4) { i++; }


I think he meant outside of for loops in function calls and declarations.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: