Short codes

How much can be achieved by only a few hundred bytes of codes? This page gives an answer.

The criteria to be included in this list:

The size is measured in bytes. All redundant white spaces (particularly, newlines added for readability) don’t count.

Under 140 bytes (fits in a tweet)

Pascal’s triangle. (@t3rmin4t0r, 73B)

main(c,r){for(r=32;r;)printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}

Perhaps the smallest ROT13 implementation in C. (Robert Harley, 78B)


A simple web framework, which translates a c parameter to the function. Requires PHP 5.3. (Fabien Potencier, 117B)

require __DIR__.'/c.php';if(!is_callable($c=@$_GET['c']?:function(){echo'Woah!';
}))throw new Exception('Error');$c();

Calculates the first 15,000 decimal digits of pi (including “3.”). Uses the unbounded spigot algorithm. (Dik T. Winter, 133B)


A simple IP stack, which can respond to pings. Designed to be usable as a tunnel. Requires sizeof(short) == 2. (Adam Dunkels, 138B)

short s[70];*l=s;t;main(){for(;;){read(0,s,140);if((s[4]&65280)==256&s[10]==8){s

Under 256 bytes

The implementation of RSA system in Perl 5 and dc(1). Receives two hexadecimal arguments, one for decryption/encryption exponent and the another for modulus. Originally conceived as a way against the regulation over the export of cryptography in US, it has undergone a number of revisions for years. (Various authors, 146B)

print pack"C*",split/\D+/,`echo "16iII*o\U@{$/=$z;[(pop,pop,unpack"H*",<>)]}\EsM

Recognizes the number 8, 9, 10 or 11 given as a bitmap of spaces and # (ends at the empty line), by calculating its Euler characteristics plus 9. Won the Best one-liner award in IOCCC 2004. This particular version differs from the award-winning program, as it required -Dif=while macro definition—hence it “has dirtiest IF”. (Eryk Kopczynski, 148B)

main(O){int I,Q,l=O;while(I=l*4){l=6;while(l>5)l+=Q-8?l-(Q=getchar()-2)%2:l;
while(Q*=2)O+="has dirtiest IF"[(I/-Q&12)-l/Q%4];}printf("%d\n",8+O%4);}

Brainfuck interpreter, where the code is given as the first argument. Supports all instructions but no comments allowed. Requires sizeof(int) == sizeof(int*) == sizeof(char*) and a set of syscalls. (Kang Seonghoon, 160B)


A program that converts a spelt number (“one hundred”) to the decimal (“100”). Supports numbers up to 1015–1. Works by filtering the unique letters (11 in this case) and constructing an octal representation of given word; it also contains a simple stemmer in order to recognize word roots. (Kang Seonghoon, 242B)

long long n,u,m,b;main(e,r){for(;n++||(e=getchar()|32)>0;b="ynwtsflrabg"[n%=11]-

Under 512 bytes

CSS descrambler implemented in C. (Charles M. Hannum, 434B)

#define m(i)(x[i]^s[i+84])<<
unsigned char x[5],y,s[2048];main(n){for(read(0,x,5);read(0,s,n=2048);write(1,s,
n))if(s[y=s[13]%8+20]/16%4==1){int i=m(1)17^256+m(0)8,k=m(2)0,j=m(4)17^m(3)9^k*2

CSS descrambler implemented in Perl. (Keith Winstein and Marc Horowitz, 472B)

b=map{ord qB8,unqb8,qT,_^$a[--D]}@INC;s/...$/1$&/;Q=unqV,qb25,_;H=73;O=$b[4]<<9


ikiwiki를 씁니다.
마지막 수정