Skip to content

Instantly share code, notes, and snippets.

/dog.hs Secret

Created May 17, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6183c5aab59117336498088c1d1d41d6 to your computer and use it in GitHub Desktop.
Save anonymous/6183c5aab59117336498088c1d1d41d6 to your computer and use it in GitHub Desktop.
import Data.List
-- Given a number, returns it's suffix
suffix n
| tens == 11 = "th"
| tens == 12 = "th"
| tens == 13 = "th"
| ones == 1 = "st"
| ones == 2 = "nd"
| ones == 3 = "rd"
| otherwise = "th"
where tens = n `mod` 100
ones = n `mod` 10
-- Converts number to Nth form
toEnglish n = show n ++ suffix n
list_places exclude total_number = take (total_number - 1) (map toEnglish places)
where places = delete exclude [0..]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment