Site hosted by Angelfire.com: Build your free website today!

MASTER MIND

(Back)
Email the author:Paolo Bonzini


Usage: the program chooses four random numbers between 1 and 6, and you have to guess them. To enter a combination type its four digits: for example, 1633. After each guess (max. 8; a "perfect player" should use at most 5, but that's hard to do) the program outputs a matrix in which every row is one of your tries: the first column is your try, the second is the number of correct digits in the wrong position, the third is the number of correct digits in the correct position.

A hint: you can discard most combinations if your first trial is a combination like 1377, i.e. of the form ABCC.

The program (a note: look at the uses of ipart and fpart to extract the digits and to perform nested loops with only one label; <> means "different", i.e. MATH/F/2):

ipart (1+6random (4))=>L3
0=>Y
{8,3}=>dim(mat A)
fill(0,mat A)

Label IN
1+Y=>Y
{Y,3}=>dim(mat A)
Input A
ipart (10fpart A{.0001,.001,.01,.1})=>L2
A=>mat A(Y,1)
L3=>L1

5=>A
Label LOOP
A-1=>A
If A=0 Goto LOOP2
If L1(A)<>L2(A) Goto LOOP
9=>L2(A)
8=>L1(A)
1+mat A(Y,3)=>mat A(Y,3)
Goto LOOP

Label LOOP2
1+ipart .25A=>B
1+4fpart .25A=>C
1+A=>A
If L1(B)<>L2(C) Goto NO
9=>L2(C)
8=>L1(B)
1+mat A(Y,2)=>mat A(Y,2)

Label NO
If A<16 Goto LOOP2

ClrT
If mat A(Y,3)=4 Goto END
Print mat A
If Y<8 Goto IN
Print L1
Label END