Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created May 22, 2012 01:17
Show Gist options
  • Save lambda-fairy/2765894 to your computer and use it in GitHub Desktop.
Save lambda-fairy/2765894 to your computer and use it in GitHub Desktop.
Soctopus Prediction
-- | <http://ncss.edu.au/challenge/ncss_challenge_2012.pdf>
class Semigroup a where
(<>) :: a -> a -> a
data Result = Team String | Draw Int
resultLength :: Result -> Int
resultLength (Team name) = length name
resultLength (Draw lgth) = lgth
instance Semigroup Result where
a <> b
| x < y = b
| x > y = a
| otherwise = Draw x
where
x = resultLength a
y = resultLength b
showResult :: Result -> String
showResult (Team name) = name
showResult (Draw _) = "Draw"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment