Live data from Hacker News

Mastermind Solver

stefanabikaram.com

21–23 of 23 posts

Re: Mastermind Solver

#22
This was my 1996 IOCCC entry, a mastermind solver. Key features are that it is a one-liner (no macros) and everything is coded using for-loops.

   char*p,*q,*r,s[50000];int i,j,k,l;main(){for(r=s,i=10000;i--;r++)for(j=i+3211,k=4;k--;*r++=48+j%10,j/=10);for(;puts((k=r-s)?q=r-5:"?"),k&&k-5;)for (scanf("%d",&k),p=s;p-r;){for(i=j=0;j-16;p[j%4]|=l=!(p[j%4]-q[j/4])?i++,64:0,j|=l/17,j++);for(j=0;j-5;i+=!((*p++&=63)-q[j++])*9);for(;k-i+9&&j--;*--p=*--r);}}
You think of a 4 digit number, the code tries to guess it. You give it 2 digit answers for red and white.

Re: Mastermind Solver

#23
Unexpectedly fun to open a HN article and have someone talk about visiting my city (Newburyport) on vacation. Hope they had a great time!

I also have a copy of Mastermind that my parents had as kids, it's probably from the 70s? Cool vibes all around, HN. :-)

Post reply on HN