10REM A clever Chinese 'mindreader'
20REM (C)1997 SPROW
30:
40MODE3
50PRINT"Chinese 'mindreader'"''"Gener
ating tables..."
60DIMbox%(4*8*6)
70REM Fill the 1st box with odd nos.
80FORodd%=1TO63STEP2
90box%(1+(odd% DIV2))=odd%
100NEXT
110:
120REM Use rules to fill the rest
130FORtable%=0TO4
140FORline%=1TO(32DIV(2^table%))
150FORindex%=1TO(2^table%)
160where%=((line%-1)*(2^table%))+index
%
170IFline% MOD2=0 THENbox%((32*table%)
+where%+32)=box%((32*table%)+where%) ELS
Ebox%((32*table%)+where%+32)=box%((32*ta
ble%)+where%)+(2^table%)
180NEXT:NEXT:NEXT
190VDU11:PRINTSTRING$(39," ")
200VDU11,11,11
210:
220REM Now print out tabulated boxes
230FORrow%=0TO11
240IFrow% MOD4=0 THENPRINT''" Table
";2*(row% DIV4)+1;SPC(27);"Table ";2*(r
ow% DIV4)+2
250PRINT'SPC(10);
260FORcolumn%=0TO15
270IFcolumn%=8 THENPRINT;SPC(10);
280PRINT;FNpad(box%(1+(column% AND7)+(
32*SGN(column% AND8))+(64*(row% DIV4))+(
8*(row% MOD4))));
290NEXT:NEXT
300:
310REM Pop the big question
320PRINT'
330REPEAT
340PRINT"Think of a number between 0 &
63... ";
350key%=INKEY(150):result%=0
360VDU11:PRINTSTRING$(39," "):VDU11
370:
380REM Interrogate the user next
390FORtable%=1TO6
400PRINT"Does your number appear in 'T
able ";table%;"' ? (Y/N)"
410REPEAT
420key%=GET AND&DF
430IFkey%=ASC"Y" THENresult%=result%+b
ox%(1+32*(table%-1))
440UNTILkey%=ASC"N" ORkey%=ASC"Y"
450VDU11
460NEXT
470:
480REM Here's my prediction
490PRINT"Well then,the number you chos
e must be ";result%;" "
500key%=INKEY(250):VDU11
510UNTIL0
520:
530DEFFNpad(number%)
540=STRING$(3-LEN(STR$number%)," ")+ST
R$number%
550:
560REM The rules for the box contents
570:
580REM The first is simply all odd
590REM numbers between 1 and 64.
600:
610REM T2R1C1=T1R1C1+1
620REM T2R1C2=no change from T1R1C2
630REM T2R1C3=T1R1C3+1
640REM T2R1C4=no change from T1R1C4
650REM ie.alternate elements
660:
670REM Table 3 is the same EXCEPT
680REM It's do 2 skip 2 do 2 skip 2
690REM and you add 2 (instead of 1)
700REM and additions are based on T2
710:
720REM Table 4 is the same EXCEPT
730REM It's do 4 skip 4 do 4 skip 4
740REM and you add 4 (instead of 2)
750REM and additions are based on T3
760:
770REM See the pattern?
780REM It's a rather cumbersome
790REM way to convert to/from binary