You are in a maze of twisty little passages ...

Some of the more obscure programming examples I have seen reminds me of my favourite piece of obscure C, from the International Obfuscated C Code Contest.

http://www.ioccc.org/years.html

Look for jason.c

To avoid copyright issues, I’ll just post an excerpt from the code:

	main(){;
	    ;;;s , ra,
	 n, d), && C ( j +R( s-j+t( i- 1) )
		   )D( W)m[ c* 4| z( j ) ]
	    &&_( X )E (d	   ( 0
		       )&&  R( 6)/ 6
			   ? c= 17|_ ( T )
			   :01,||+
			       , v =i & 3 ^ 2
			       ,+j & 3&&W ( j)||y ( 10 )D (k) --
				   j ? k ( O[j]=R(15 ))
: 1 D
			 ( H )o ( 7+! !  i+3 )+

				  i?

The rest is very similar. It still compiles, certainly under Mac OS/X 10.6.7 (if you have the development tools installed). It also compiles under Cygwin, if you are using Windows.

To compile and run:

$ gcc jason.c -o jason
$ ./jason

Example output:

you are in a maze of twisty little passages
caves lead:  left forward right back
you see
   a lamp
> get lamp
done
> f
you climb...
you are in a maze of twisty little passages
caves lead:  left forward right back
> f
you climb...
you are in a maze of twisty little passages
caves lead:  left forward right back
> f
you climb...
you are in a maze of twisty little passages
caves lead:  left forward right back
> r
you climb...
you are in a maze of twisty little passages
caves lead:  left right back
you see
   a zither
> get zither
done
> r
you climb...
you are in a maze of twisty little passages
caves lead:  left forward right back
> f
you climb...
you are in a maze of twisty little passages
caves lead:  left forward right back

The fascinating thing is that, the source code is only 3.8 Kb in size. It is just the one .C file (no data files or anything like that). And there is no appearance of the words “cave” “passages” “zither” or anything remotely recognisable as an adventure game in it.

According to the program’s hints:

The goal is to collect 8 treasures (plus the lamp) and escape into the sunlight - or moonlight, as the case may be. After a few minutes, the lamp runs out of oil, and things become perilous.

If you manage to escape, you score 50 points for your hide, 50 points per item, and bonus points for speed.

Running the program through the C preprocessor and looking at the output doesn’t really help:

<9 + 2?__[ * p ]: * p+ 7 +79):o( j+1) : o (26+j),&q ( -! * p ++ + i )D(x)i? a=x ( ( -- i)), ++ p ) 
D( t ) i""( b= 60 + time ( 0)+ 60 * 4) ;""B? B ?B ?B? B ?B ?B ?7 :B?B ?36: 59 * 89 *5 * 2 :B?6587 *77 :9 
+ 2:B ?B?B?9: 5 : 37 : B ? 5 +5:4:20: B?B?B?32 :e( 4, 3 , 1 *4 * 59 * 1 , 7):B? 17: 34 : 19 :B ? 8 *2 :B 
? 2:26: B? B?B ?B ? 82 *+ 576: B ?33 :22 :5 * 5:3 *4 :3:B ?B ?B? B ?6 + + 17 : B?B?13:6 : 9 *2:B?15 : 7 
*2 : B ? B ? 27:24: 31 : B? B? + 29 :""&& C ( j +R( s-j+t( i- 1) ) )D( W)m[ c* 4| z( j ) ] &&_( X )E (d 
( 0 )&& R( 6)/ 6 ? c= 17|_

All credit to the original author of the code: Jason Orendorff

What's obfuscated about that, it looks just like my code.

And I've spotted a bug

v =i

should be

v == i

God knows how it worked at all with that.


Rob

XD