-
-
Save anonymous/6183c5aab59117336498088c1d1d41d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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