# Maths Puzzles

## Casio fx-50

Here are some programs for the Casio fx-50 calculator. Enter the code into any of the program areas.

–> is the arrow key. Quicker to use the STO button.
=> is the 'then' operator.
# is the 'display result' black down-right triangle.
<> is the 'not equal' operator.
>= is the 'greater than or equal' operator.
<= is the 'less than or equal' operator.

### Number Reverse

Reverses the number in the display. So 1234 will reverse to 4321. Any leading zeros are removed, so 1000 will become just 1.

Base mode, 49 bytes.

Ans–>A: 0–>B:
While A<>0:
10B+A–10(A/10–>B:
A/10–>A:
WhileEnd: B#

### Code generator

Generates a 'string' of four A-F characters and stores in register A. Shows 8888 when done. Note that this will only look correct when A is recalled in Base 16 (Hex) mode.
Of course, you could always ask someone to create a random code for you!
This program can be used with MasterMind below.

Comp mode, 57 bytes.

Fix 0: 0–>A:
For 0–>C To 3:
Lbl 1:
Rnd(10Ran#–>X:
X<2 => Goto 1:
X>7 => Goto 1:
A+((X+8)(16^(C–>A:
Next: 8888#

### MasterMind

This plays the MasterMind game with 6 colors and 4 holes. You need to enter the code above to generate a random code. Then enter your 4 color guess with the A-F keys. I think the color names are:

A - Aqua marine
B - Blueberry
C - Crimson
D - Daffodil
E - Emerald
F - Fuchsia

After each try, the display shows the number of black and white pegs. So 12 means 1 black and 2 white pegs. There are no leading zeros, so 3 means just 3 white pegs.

When the code is guessed correctly, the code is displayed eg ABCD40.
You can enter 8 anytime to peek at the answer.
The program is optimised to skip (not check) previously 'paired' colors.

Base mode, 255 bytes.

Fix 0: Hex: 0–>X: 100A–>M:

Lbl 0:
M/100–>A: 100A–>M:
1000–>D: ?–>X:
X=0 => Goto 0:
If X=8: Then A# Goto 0: IfEnd:

For 1–>C To 4:
A–10(A/10–>B: A/10–>A:
X–10(X/10–>Y: X/10–>X:

If B=Y: Then
10M+: D/10–>D:
Else
A+DB–>A:
X+DY–>X:
IfEnd:
Next:

While A>0:
A–10(A/10–>B: A/10–>A:
D–>C:
Lbl 1:
X–10(X/10–>Y: X/10–>X:

If B=Y: Then
1M+:
0–>C: D/10–>D:
Else
X+DY–>X:
IfEnd:

C/10–>C:
C>0=>Goto 1:
WhileEnd:

M–100(M/100–>X:
X<40=>Goto 0:
M#

 cr31.co.uk