[comp.sources.bugs] v04i110: An amazingly small C-program

jv@mhres.mh.nl (Johan Vromans) (10/02/88)

From article <7656@boring.cwi.nl>, by tromp@cwi.nl.UUCP (John Tromp):
> Posting-number: Volume 4, Issue 110
> Submitted-by: "John Tromp" <tromp@cwi.nl.UUCP>
> Archive-name: mazemaze

Compile and run on a BSD4.3 system (Gould Powernode 6000 / UTX2.0):
[lines truncated on behalf of mailers]:
} ._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
} | ._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._|_._. ._|
} | ._|_| |_. | | | | ._._|_._|_._. . |_. | | | ._._| |_._.
} |_._._._. | ._|_. ._._._. | | ._. |_._. . | ._._| |_. | .
} | | . |_._| . ._._._| ._._. ._._| | | |_| . | |_. . ._|_|
} |_._|_._._._|_._._._|_|_._._._|_._|_._._._|_._._._|_._._.

Compile and run on a System V.3 system (NatSem 32332 based):
[lines truncated on behalf of mailers]:
} ._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
} |_._._._._._._._._._._._._._._._._._._._._._._._._._._._.

Compile on HP9000/320 with HP-UX 5.3:

} "x.c", line 7: compiler error: register allocation error

Compile on VAX/VMS 4.5 with VAX-C 2.1:

} %CC-E-NOTPOINTER, Address-valued expression not found.
}                 At line number 5 in MH$ROOT:[JV]X.C;1.
} 
} %CC-I-NOBJECT, No object file produced.
}                 At line number 7 in MH$ROOT:[JV]X.C;1.
} 
} %CC-I-SUMMARY, Completed with 1 error(s), 0 warning(s), and
}                 1 informational messages.
}                 At line number 7 in MH$ROOT:[JV]X.C;1.


Amazing, isn't it?
-- 
	Johan

ip@hammer.me.toronto.edu (10/04/88)

In article <2456@mhres.mh.nl> jv@mhres.mh.nl (Johan Vromans) writes:
>From article <7656@boring.cwi.nl>, by tromp@cwi.nl.UUCP (John Tromp):
>> Posting-number: Volume 4, Issue 110
>> Submitted-by: "John Tromp" <tromp@cwi.nl.UUCP>
>> Archive-name: mazemaze
>
>Compile on HP9000/320 with HP-UX 5.3:
>
>} "x.c", line 7: compiler error: register allocation error
>
>Compile on VAX/VMS 4.5 with VAX-C 2.1:
>
>} %CC-E-NOTPOINTER, Address-valued expression not found.
>}                 At line number 5 in MH$ROOT:[JV]X.C;1.
>} 
>} %CC-I-NOBJECT, No object file produced.
>}                 At line number 7 in MH$ROOT:[JV]X.C;1.
>} 
>} %CC-I-SUMMARY, Completed with 1 error(s), 0 warning(s), and
>}                 1 informational messages.
>}                 At line number 7 in MH$ROOT:[JV]X.C;1.
>
>
>Amazing, isn't it?
>-- 
>	Johan

To add to the list, On a SUN3/60:

% cc t.c
% a.out
core dump
%

Yup, I have to agree, it're really amazing.

bevis
-- 
Bevis Ip   <ip@me.utoronto.ca>	| CSNET :  ip@me.toronto.edu
University of Toronto		| BITNET:  ip@me.UTORONTO
Dept. of Mechanical Engineering	| ARPA  :  ip%me.toronto.edu@relay.cs.net
Toronto, Ont. Canada		| UUCP  :  {allegra,decwrl,decvax}!utcsri!me!ip
VOICE : (416) 978-6443		|	   {pyramid,uunet}!utai!me!ip

bobmon@iuvax.cs.indiana.edu (RAMontante) (10/06/88)

...runs on an MSDOS box under TurboC, but the random isn't random
and it's a very regular "maze".  The code's kind of cute, though.
-- 
--    bob,mon			(bobmon@iuvax.cs.indiana.edu)
--    "Aristotle was not Belgian..."	- Wanda

jfh@rpp386.Dallas.TX.US (The Beach Bum) (10/06/88)

I changed the `27' on the bottom line to an `11'.  This reflects rand()'s
return numbers in the range 0 .. 32767.  The comparision of rand() against
6 << 27 never flew ...

I also added a call like srand (getpid ()).  This produced a more random
maze but didn't look as pretty.

- John.
-- 
John F. Haugh II (jfh@rpp386.Dallas.TX.US)                   HASA, "S" Division

      "Why waste negative entropy on comments, when you could use the same
                   entropy to create bugs instead?" -- Steve Elias

ralph@rtech.rtech.com (Ralph Harnden) (10/06/88)

In article <2456@mhres.mh.nl> jv@mhres.mh.nl (Johan Vromans) writes:
>From article <7656@boring.cwi.nl>, by tromp@cwi.nl.UUCP (John Tromp):
>> Posting-number: Volume 4, Issue 110
>> Submitted-by: "John Tromp" <tromp@cwi.nl.UUCP>
>> Archive-name: mazemaze
>...
>Compile and run on a System V.3 system (NatSem 32332 based):
>[lines truncated on behalf of mailers]:
>} ._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
>} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
>} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
>} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
>} | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
>} |_._._._._._._._._._._._._._._._._._._._._._._._._._._._.
>...

Similar results on my 3B1.  Problem is rand(3C) returns int between -2**15+1
and 2**15-1, but the code expects int between 0 and 2**31-1.  Change rand()
to lrand48().  Or change "6<<27<rand()" to "6<<11<abs(rand())".  May work 4U.
-- 
"People will do anything for a potato"

{amdahl, mtxinu, ptsfa, sun}!rtech!gusano!ralph ralph@gusano@rtech.com

ralph@rtech.rtech.com (Ralph Harnden) (10/06/88)

In article <21617.1988Oct3.14:18:27@hammer.me.toronto.edu> ip@me.toronto.edu (Bevis Y W Ip) writes:
>In article <2456@mhres.mh.nl> jv@mhres.mh.nl (Johan Vromans) writes:
>>From article <7656@boring.cwi.nl>, by tromp@cwi.nl.UUCP (John Tromp):
>>> Posting-number: Volume 4, Issue 110
>>> Submitted-by: "John Tromp" <tromp@cwi.nl.UUCP>
>>> Archive-name: mazemaze
>>
>...
>To add to the list, On a SUN3/60:
>
>% cc t.c
>% a.out
>core dump
>%

Did you type a number when the program attempted to read from stdin?  It's
not on your bug description.  Try the program again, and when it reads, 
enter a nice, big number.
-- 
"People will do anything for a potato"

{amdahl, mtxinu, ptsfa, sun}!rtech!gusano!ralph ralph@gusano@rtech.com

res@cbnews.ATT.COM (Robert E. Stampfli) (10/08/88)

>In article <751@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes:
>>I include the source here for reference--it's very short:
>
>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,"_.":" |"];}
  ^^^^^
>

When I tried compiling this, it didn't work, generating mazes which were
always columnar except for one horizontal row at the bottom.

However, by changing the "6<<27" to "4<<11" I found it worked
for my "big-endian" type machines.  The rand() function returns a
number in the range 0 - 2^15-1 on my systems, making the program 
always fail the comparison, as originally written.  Other systems
may have slightly different rand() functions, I suppose.  Regardless,
this is one jewel of a program.  Hope this helps someone.

Rob Stampfli
att!cbnews!res

maujp@warwick.ac.uk (Steven Shipway) (10/10/88)

 Well, I compiled it on a Sun 3/160 and on a Gould, and on a Sun4, and
every time it worked perfectly. I thought it was an interesting diversion,
especially if you deliberately obfuscate it a bit more and then challenge
someone to decode it...

-Steve
maujp@uk.ac.warwick.cu
...!uunet!mcvax!ukc!warwick!maujp
-----------------------------------------------------------------------------
#include <quote.h>