sábado, 21 de noviembre de 2009

Mastermind in scheme

3 Days ago I read a post on programming praxis blog about writing a mastermind
game. The author splitted the game in two parts, the first
being the setter
, so given a known solution, and a guess, returns a string
of B/W/.

The point is that when I tried to code it, I was in an internetless bar, so I
had to guess some parts of the exercise and I missunderstod some of the points
and the code didn't work as expected (but at least, I succeeded to make it work
as I thought it had to work)

When looking the solution proposed at programming praxis, I payed attention to
both the algorithm used, and the code.

The algorithm used is works calculating white pegs, and then substract black
pegs. Finally, it sorts the black and white pegs and prints the output.

I'll try to write my own version in near future, but, for the moment, I have
updated the perl Mastermind code I started some time ago, that until now, it only compared the solution to the given combination, and returned a good/bad value. Now it uses that algo to tell how accurated is your guess. It's still far from functional, (it only plays random (with or without repetitions (using a cache))), but I have little time to hack on those projects.

I will have to take a look at the programming praxis "standard prelude", where the author shows some generic functions that are used over his solutions.

Btw, Programming Praxis has been one of my last findings on the intertubez. A great find IMHO.