
import System.IO
import System.FilePath
import Data.List
import Data.List.Split

days = ["first", "second", "third", "fourth", "fifth", "sixth",
        "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]

nums = ["a", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
                                    "Nine", "Ten", "Eleven", "Twelve"]

song :: [String] -> [String]
song [] = []
song cnts =  (verse (length cnts) cnts)
            ++ (phrase (length cnts))
            ++ (song ( tail cnts))

verse :: Int -> [String] -> [String]
verse day items = reverse $ allItems (day-1) items

phrase :: Int -> [String]
phrase day = ["\nOn the " ++ days!!(day-1) ++ " day of Christmas\nmy true love sent to me:"]

allItems :: Int -> [String] -> [String]
allItems _ [] = []
allItems day (item:items) = (combo day item):(allItems (day-1) items)

combo :: Int -> String -> String
combo 0 item =  "and " ++ nums!!0 ++ " " ++ item
combo day item = nums!!day ++ " " ++ item

h_print :: Int -> String -> IO ()
h_print 0 a = putStrLn $ take (length a) (drop 1 a)
h_print 1 a = putStrLn $ take (length a ) (drop 4 a)
h_print _ b = putStrLn b

main :: IO [()]
main = do
    contents <- readFile "..\\twelve_input_1.txt"
    let lyrics = zip [0,1..] $ reverse . song . reverse $ lines contents
    do
        mapM (uncurry $ h_print) lyrics


