The Twelve Days of Christmas: Difference between revisions

Content added Content deleted
m (→‎{{header|Terraform}}: simplify range use)
m (→‎{{header|Haskell}}: Applied Ormolu)
Line 2,032: Line 2,032:
{{trans|F#}}
{{trans|F#}}
<lang haskell>gifts :: [String]
<lang haskell>gifts :: [String]
gifts = [
gifts =
"And a partridge in a pear tree!",
[ "And a partridge in a pear tree!",
"Two turtle doves,",
"Two turtle doves,",
"Three french hens,",
"Three french hens,",
Line 2,044: Line 2,044:
"Ten lords a-leaping,",
"Ten lords a-leaping,",
"Eleven pipers piping,",
"Eleven pipers piping,",
"Twelve drummers drumming," ]
"Twelve drummers drumming,"
]


days :: [String]
days :: [String]
days = [
days =
[ "first",
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
"second",
"ninth", "tenth", "eleventh", "twelfth" ]
"third",
"fourth",
verseOfTheDay :: Int -> IO ()
"fifth",
"sixth",
"seventh",
"eighth",
"ninth",
"tenth",
"eleventh",
"twelfth"
]

verseOfTheDay :: Int -> IO ()
verseOfTheDay day = do
verseOfTheDay day = do
putStrLn $
putStrLn $ "On the " ++ days !! day ++ " day of Christmas my true love gave to me... "
mapM_ putStrLn [dayGift day d | d <- [day, day-1..0]]
"On the " <> days !! day
<> " day of Christmas my true love gave to me... "
putStrLn ""
where dayGift 0 _ = "A partridge in a pear tree!"
mapM_ putStrLn [dayGift day d | d <- [day, day -1 .. 0]]
putStrLn ""
dayGift _ gift = gifts !! gift
where
dayGift 0 _ = "A partridge in a pear tree!"
dayGift _ gift = gifts !! gift


main :: IO ()
main :: IO ()
main = mapM_ verseOfTheDay [0..11]
main = mapM_ verseOfTheDay [0 .. 11]</lang>
</lang>
{{out}}
{{out}}
<pre style="font-size:80%">On the first day of Christmas my true love gave to me...
<pre style="font-size:80%">On the first day of Christmas my true love gave to me...
Line 2,163: Line 2,177:
Three french hens,
Three french hens,
Two turtle doves,
Two turtle doves,
And a partridge in a pear tree!
And a partridge in a pear tree!</pre>

</pre>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==