Skip to content

Instantly share code, notes, and snippets.

@mdippery
Last active August 29, 2015 14:16
Show Gist options
  • Save mdippery/924d024444cad0447d8a to your computer and use it in GitHub Desktop.
Save mdippery/924d024444cad0447d8a to your computer and use it in GitHub Desktop.
Calculates Chinese zodiac sign for a given year
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs)
offset = (flip mod) 12
animal 4 = "Rat"
animal 5 = "Ox"
animal 6 = "Tiger"
animal 7 = "Rabbit"
animal 8 = "Dragon"
animal 9 = "Snake"
animal 10 = "Horse"
animal 11 = "Sheep"
animal 0 = "Monkey"
animal 1 = "Rooster"
animal 2 = "Dog"
animal 3 = "Pig"
parseArgs = getOpt RequireOrder []
main = do
argv <- getArgs
let year = case parseArgs argv of
([], year:_, []) -> read year :: Int
putStrLn $ animal $ offset year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment