Skip to content

Instantly share code, notes, and snippets.

@dbushong
Created July 14, 2010 00:07
Show Gist options
  • Save dbushong/474782 to your computer and use it in GitHub Desktop.
Save dbushong/474782 to your computer and use it in GitHub Desktop.
module Main where
import Random
import List
p=putStrLn
f(x,y)=x\\(x\\y)
e z=['*'|(p,q)<-z,p==q]++(f(unzip[x|x@(p,q)<-z,p/=q])>>"+")
n a s=getLine>>=m where{m i|i==s=return a;m i=p(e$zip i s)>>n(a+1)s}
main=mapM(\x->randomRIO('1','6'))"mind">>=n 1>>=p.("Tries: "++).show
$i=join'',@i=map{1+0|rand 6}1..4;while(<>){chop;$s=$_;split//;$a=grep{$_[$_]==$i[$_]}0..3;$a>3&&last;print'*'x$a,'+'x((grep{$s=~s/$_//}@i)-$a),"
"}print"Tries: $.
"
j=0..3;x=j.map{(6*rand).ceil};t=0;while gets
g=$_.chomp.split('').map{|c|c.to_i};t+=1;if
g==x;puts "Tries: #{t}";exit;end;y=x.clone
puts (j.map{|i|x[i]==g[i]?g[i]=y[i]=0:2}+g.uniq.map{|i|i>0&&y.member?(i)?1:2}).map{|i|['*','+',''][i]}.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment