4 ms·
My 1988 submission to the International Obfuscated C Code Contest was this maze generator: char*M,A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf(M="%d",&C);
by tromp 3y ago
My 1988 submission to the International Obfuscated C Code Contest was this maze generator:
char*M,A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf(M="%d",&C);
-- E; J[ E] =T
[E ]= E) printf("._"); for(;(A-=Z=!Z) || (printf("\n|"
) , A = 39 ,C --
) ; Z || printf (M ))M[Z]=Z[A-(E =A[J-Z])&&!C
& A == T[ A]
|6<<27<rand()||!C&!Z?J[T[E]=T[A]]=E,J[T[A]=A-Z]=A,"_.":" |"];}
expecting a number on stdin and then generating a maze of that height line by line. For a negative number it will effectively produce an endless maze. As it turned out I had independently rediscovered Eller's algorithm (https://weblog.jamisbuck.org/2010/12/29/maze-generation-eller-s-algorithm https://weblog.jamisbuck.org/2010/12/29/maze-generation-elle...).
Note that the constant 27 assumes a 31-bit random number generator, and needs to be replaced with 11 if rand() produces 15-bit numbers instead. Modern C compilers don't allow constant strings to be overwritten, which can be avoided by changing the first line to
char M[3],A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf("%d",&C);
The program is explained in detail in https://tromp.github.io/maze.html https://tromp.github.io/maze.html
- guenthert 3y ago> Modern C compilers don't allow constant strings to be overwritten One compiler available on contemporary Linux distributions still able to handle not so modern C is Fabrice Bellard's Tiny C Compiler, tcc.