Comment by tromp
15 hours ago
A maze generator in the shape of a maze whose corridors spell a 4-letter word:
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,"_.":" |"];}
Generates a maze on the fly after entering the desired height of the maze. This compiled fine back in 1988 when I submitted it to the IOCCC (having rediscovered Eller's algorithm). 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 code is explained in detail at https://tromp.github.io/maze.html
Neat!
Related: Here's a C program that draws random dungeons sort of like you use in a roguelike dungeon crawler:
If I squeeze the eyes I can read the "MAZE". :)
Sadly neither version works here with an older clang on OS X. Both variants build fine with 9 warnings each. But the old variant dies with a "Bus Error: 10", and the new variant with "Segmentation fault: 11". Same with gcc (albeit only 8 warnings.)
/edit
OK, just wrong user input. You gotta feed it a number, and not a "foobar" or another random string.
Amazing! I read you article in 2012 when the link was https://homepages.cwi.nl/~tromp/maze.html I was learning Haskell and Ocaml and wrote my own article in Chinese then https://maskray.me/blog/2012-11-02-perfect-maze-generation
Now I should fix the link.