home *** CD-ROM | disk | FTP | other *** search
- #!/depot/path/expect -f
- # Script to solve Jim Bonfield's game that won the 1991 Obfuscated C contest.
- # Originally written by Don Libes, NIST, 1/3/91, later rewritten using
- # John Tromp's highly optimized set of moves
-
- # If you want to play part of the game, just put in an "interact;exit"
- # anywhere and expect will do the first part, leaving the rest for you!
- # (That was how I solved the game in the first place - by pushing the
- # interact further and further back as I figured things out.)
-
- proc do {moves} {send $moves; expect *}
-
- trap exit SIGINT
- set timeout 1000;# need a long timeout because expect can get far enough
- # ahead of the game that by the final expect, we have to
- # wait quite a bit for the I/O to complete!
- spawn puzzle
-
- # In the opening scene, we don't know exactly what to watch for (a lota #s?),
- # so just wait for a 1000 or so characters to go by!
- set count 0
- while {$count<1000} {
- expect -re .+
- incr count [llength [split $expect_out(buffer) ""]]
- }
-
- # opening
- do kkklllllljjlll; # to key room
- do kkllljjhjkhhhhh; # make gems, push left-key-1 into door
- do lllllkkll; # to key room & pick up gems in upper-right-hand corner
- do jjjhjjjjhkhkhhk; # take remaining gems, push up-key free
- do jllk; # push boulder up as long as we're here
- do jjllkkhkkkhhjjl; # manipulate left-key-2 and boulder
- do hhhhhhh; # push up-key into door-room
- do jhkkllllll; # unlock door and go back to key room
- do jjllklkhhhhhhhh; # get behind left-key-2 and push into door room
- do lllkkhhhhjj; # leave left-key-2 next to door
- do lllllllkkhjljhhhhhh; # go back to key-room, return with down-key
- do jhhhhkkklljjkkhhjjjllklj; # unlock two remaining doors
- # retrieve boulder from key room and smash into boulder at bottom
- do llllllkklljjkklljjjhhljjhhkklkhhhhhhhhlllkkhhhhjjkkhhjjjllkljjjjjjjj
- do hkkkkhhhllkk; # go back up, making/picking up gems along the way
- do hhhhkhkkkhjjjjlllll; # make/collect gems from upper-left-hand corner
- do kljjjjjjhjhllll; # move remaining boulder down, pick up remaining gems
- do hkkllkkkkjjj; # make/pick up gems from central chute
- do ljjhkkkk; # move uncompressible into shute
- do ljjjhjlll; # move boulder out of shute, make/pickup gems on bottom
- do klljllkhhhhhlll
- do lljlllhkhhhhhhjhkkk; # move another unc into shute
- do jjlllllllljlkklkkkhjhjljjhhkljl; # get beneath boulder, prepare to lift
- do kkkkkklkhkl; # pick up lots of gems
- do kkhjjjjjljhkhjjlj; # get behind key, prepare to move to door
- do hhhhhhhhjhklkhhhhhhhhhk; # unlock door, enter & pick up a gem
- do hkhljjjjh;# pick up remaining gems
- do jllkhklllllllkljhjlllllllllll; # move last boulders together
- # send final command by hand to wait for congrat message
- send l
- expect -re "Well done!"
-