Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

A mastermind puzzle

Name: Anonymous 2012-09-27 15:26

You're playing mastermind, an algorithmic and logical game (if you don't know the rules, you can google them). You've posed the following guesses so far, and got the following results (x is RIGHT color, RIGHT location, o is RIGHT color, WRONG location):

OYPR -- xx
YBOW -- xo
BWYY -- o

What one guess can you make, that regardless of being correct, will give you a definitive answer as to what the code is?

Name: Anonymous 2012-09-27 15:29

is the last line incomplete?

Name: Anonymous 2012-09-27 15:40

All of the information needed is there.

Name: Anonymous 2012-09-27 15:45

BWYY -- o
really? fine, WYPR

Name: Anonymous 2012-09-27 17:13

Incorrect. Feel free to try again.

Name: Anonymous 2012-09-27 17:15

what does the location mean, you give 2 answers for 4 stmbols

Name: Anonymous 2012-09-27 17:33

The location of the symbols is not indicative of correct placement. Given four 'colors' (or letters in this case) and two answers, two colors are neither correct, nor correct in the right place.

Name: Anonymous 2012-09-27 17:41

yogk

Name: Anonymous 2012-09-27 17:42

YHBT

Name: Anonymous 2012-09-27 18:23

I think there are only 6 possible combinations >>1-kun could have - namely:

O B P P
O B P B
O B P O
O B R R
O B B R
O Y O O
O O P W

Is this correct?
My guess would then obviously have to be such, that the answer from mastermind would be different for every possible given combination.

Name: >>10 2012-09-27 18:28

Whoops, I wrote ``6 combinations'' but gave 7 - I think there are 7 possible combinations.

Name: Anonymous 2012-09-27 19:49

#lang racket/base

(require (planet murphy/amb:1:1/amb))
(require racket/list)

(define (right x y) (count eq? x y))
(define (right-color* x y)
  (cond
    ((null? x) 0)
    ((memq (car x) y) (+ 1 (right-color* (cdr x) (remq (car x) y))))
    (else (right-color* (cdr x) y))))
(define (right-color x y) (- (right-color* x y) (right x y)))

(define (configuration) (build-list 4 (lambda (_) (amb 'P 'R 'B 'Y 'W 'O))))

(define (assert-possible guess actual g-right g-color)
  (amb-assert (= g-right (right guess actual)))
  (amb-assert (= g-color (right-color guess actual)))
  )

(define possible
  (amb-collect
   (let ((actual (configuration)))
     (assert-possible '(O Y P R) actual 2 0)
     (assert-possible '(Y B O W) actual 1 1)
     (assert-possible '(B W Y Y) actual 0 1)
     actual
     )))

(define guesses
  (amb-collect
   (let ((guess (configuration)))
     (for ((actual possible))
       (let*
           ((g-right (right guess actual))
            (g-color (right-color guess actual))
            (left
             (amb-collect
              (for/amb ((p possible))
                (assert-possible guess p g-right g-color)
                p))))
         (amb-assert (= 1 (length left)))))
     guess)))

(for ((g guesses))
  (printf "guess ~a~n" g)
  (for ((p possible))
    (let ((g-right (right g p)) (g-color (right-color g p)))
      (printf "~a ~a ~a~n" p g-right g-color))))


Output:
guess (P B B P)
(O P P W) 0 2 
(O B P P) 2 1 
(O B P B) 1 2 
(O B P O) 1 1 
(O B R R) 1 0 
(O B B R) 2 0 
(O Y O O) 0 0 
(O O P W) 0 1 
guess (B P P B)
(O P P W) 2 0 
(O B P P) 1 2 
(O B P B) 2 1 
(O B P O) 1 1 
(O B R R) 0 1 
(O B B R) 0 2 
(O Y O O) 0 0 
(O O P W) 1 0 

Name: Anonymous 2012-09-27 19:57

>>12
Should have used JS!

Name: Anonymous 2012-09-28 5:51

This is a good thread.

Name: Anonymous 2012-09-28 8:42

>>13
That's great, except JS doesn't automatically do TCO.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List