Skip to content

Instantly share code, notes, and snippets.

@msakai
Created February 28, 2011 03:06
Show Gist options
  • Save msakai/846879 to your computer and use it in GitHub Desktop.
Save msakai/846879 to your computer and use it in GitHub Desktop.
type S = ((Int,Int),(Int,Int),(Int,Int))
guess :: S -> S
guess ((a1,a2),(b1,b2),(c1,c2)) =
case (a1+b1) `compare` (b2+c1) of
EQ ->
if b1 < b2
then ((100,99),(99,100),(99,100))
else ((99,100),(100,99),(100,99))
LT ->
case (a1+c1) `compare` (a2+c2) of
EQ -> ((99,100),(99,100),(100,99))
LT -> ((99,100),(99,100),(99,100))
GT -> ((100,99),(99,100),(100,99))
GT ->
case (a1+c1) `compare` (a2+c2) of
EQ -> ((100,99),(100,99),(99,100))
LT -> ((99,100),(100,99),(99,100))
GT -> ((100,99),(100,99),(100,99))
test :: S -> Bool
test s = guess s == s
testAll :: Bool
testAll = and [test (as,bs,cs) | as <- xs, bs <- xs, cs <- xs]
where xs = [(99,100),(100,99)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment