(11C) Code guessing game
04-26-2018, 06:57 PM (This post was last modified: 05-02-2018 08:23 PM by Dieter.)
Post: #4
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (11C) Code guessing game
(04-25-2018 06:18 PM)Rogier Wrote:  Also known as "Mastermind". I wrote it somewhere around 1985. The calculator takes a number of 3-10 digits and up to 9 colours for you to guess. C starts a new game, D enters a guess. Result: number in the form a,b where a = number of digits with right colour, and b is the number of digits of the right colour which are in the right place. Or: number FIX9 > you guessed it.

Ah, Mastermind / Bagels / Code Breaker – one of the first useful programs I wrote for the 34C back then. I used a different approach that stored the code digits in individual registers. And the code always consisted of four different colors.

(15C commands in brackets, where required)

Code:
001  LBL A 002  CLX 003  STO 0 004  4 005  STO ,0 006  LBL 1 007  RCL 0 008  STO I 009  RAN# 010  6 011  x 012  INT 013  1 014  + 015  LBL 2 016  RCL(i) 017  x<>y 018  X=Y?   (TEST 5) 019  GTO 1 020  DSE    (DSE I) 021  GTO 2 022  RCL 0 023  1 024  + 025  STO 0 026  STO I 027  R↓ 028  STO(i) 029  RCL 0 030  RCL ,0 031  X>Y?   (TEST 7) 032  GTO 1 033  CLX 034  STO 9 035  LBL 0 036  FIX 1 037  R/S 038  LBL B 039  STO 7 040  RCL ,0 041  STO 0 042  CLX 043  STO 8 044  1 045  STO+9 046  LBL 3 047  RCL ,0 048  STO I  049  1 050  0 051  STO÷7 052  RCL 7 053  FRAC 054  STO-7 055  x 056  LBL 4 057  RCL(i) 058  x<>y 059  X=Y?   (TEST 5) 060  GTO 6 061  DSE    (DSE I) 062  GTO 4 063  GTO 5 064  LBL 6 065  RCL 0 066  RCL I 067  X≠Y?   (TEST 6) 068  , 069  1 070  STO+8 071  LBL 5 072  1 073  STO-0 074  RCL 0 075  X>0?   (TEST 1) 076  GTO 3 077  RCL ,0 078  RCL 8 079  X≠Y?   (TEST 6) 080  GTO 0 081  RCL 9 082  10^x 083  x 084  SCI 1 085  RTN Registers: R0: pointer / counter R1...R6: code digit 1...6 R7: guess R8: score R9: guess counter R,0: code length

Edit: changed the roles of R,0 and R7 for 11C compliance and removed an obsolete line.

Hint for 15C users – you may replace the final lines after "GTO 0" with RCL 9  FIX 0  SF 9  RTN. If the code has been correctly guessed this yields a flashing display with the number of required guesses. ;-)  You can also replace line 72...75 with DSE 0.

The code length is set in line 005, change it as desired to something between 1 and 6.
The number of different colors is set in line 010. Must be ≥ code length and ≤ 9.
Default is a 4-digit code with each digit between 1 and 6. For your first attemps you may change this to a 3-digit code with 5 colors.

[A] generates the code => 0,0

Enter your guess and press [R/S] or [B] => x,y
Here x is the number of right colors in the right place, and y is the number of colors that are correct, but in the wrong position.

Example:

[A] => 0,0

Note: generated code is assumed to be 4532

1234 [B] => 1,2
1325 [B] => 0,3
3254 [B] => 0,4
2534 [B] => 2,2
2435 [B] => 1,3
4532 [B] => 4,0       06

So you finally got all 4 colors right and required 6 guesses.

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread (11C) Code guessing game - Rogier - 04-25-2018, 06:18 PM RE: (11C) Code guessing game - Michael Zinn - 04-25-2018, 08:50 PM RE: (11C) Code guessing game - Michael Zinn - 04-25-2018, 10:58 PM RE: (11C) Code guessing game - Dieter - 04-26-2018 06:57 PM RE: (11C) Code guessing game - Rogier - 04-26-2018, 10:10 PM RE: (11C) Code guessing game - Dieter - 04-27-2018, 06:54 AM RE: (11C) Code guessing game - Dieter - 04-27-2018, 12:52 PM RE: (11C) Code guessing game - Michael Zinn - 04-28-2018, 07:10 PM RE: (11C) Code guessing game - Rogier - 04-28-2018, 12:24 PM RE: (11C) Code guessing game - Dieter - 04-29-2018, 09:00 PM RE: (11C) Code guessing game - pier4r - 04-28-2018, 07:23 PM RE: (11C) Code guessing game - Rogier - 04-29-2018, 09:58 PM RE: (11C) Code guessing game - Dieter - 04-30-2018, 08:11 AM RE: (11C) Code guessing game - Rogier - 04-30-2018, 07:29 PM RE: (11C) Code guessing game - SlideRule - 07-23-2018, 03:22 PM RE: (11C) Code guessing game - Rogier - 05-02-2018, 06:49 PM RE: (11C) Code guessing game - Thomas Klemm - 07-23-2018, 01:14 AM RE: (11C) Code guessing game - Nihotte(lma) - 05-31-2020, 07:43 PM

User(s) browsing this thread: 1 Guest(s)