As you may know, some time ago I started not one but two implementations of mastermind.
One in Perl, and the other in Scheme.
I wanted to finish the scheme implementation, so I started to look at Donald Knuth's paper about Mastermind. It's not so complicated, but as I've been far from complex algorithms for some time, it scared me a bit.
First thing to do is having available all possible combinations (strictly speaking they are permutations as order matters) of colours (in our case numbers). Two nested maps, a recursive call, and you're done.
As I don't have time to comment all the code, I'll just post here the permutations part, and keep the complete code private for now. When I have the time, I'll post it all, with appropiate comments. It's a minimax algorithm, so not daunting at all, but....
Here it is:
Apart from this, I've hacked with a few things (as time permitted). If you're specially interested in something, ask.
- net sniffing
- Image analyzing and video tracking
- html parsing and web scraping