import Control.Applicative
import System.Random
import Data.Tuple
import Data.List
main :: IO ()
main = mapM_ printChristmasTree [1..7]
printChristmasTree :: Int -> IO ()
printChristmasTree n = christmasTree <$> getStdGen <*> pure n >>= putStrLn
christmasTree :: StdGen -> Int -> String
christmasTree gen h = unlines $ center w $ concat [["☆"], body, ["||"]]
where
body = snd $ mapAccumL ((swap .) . flip splitAt) a [2, 4 .. w]
a = map (chars !!) $ randomRs (1, length chars - 1) gen
w = 2 * (h - 1)
center :: Int -> [String] -> [String]
center w xs = map padding xs
where
padding s = replicate ((w - length s) `div` 2) ' ' ++ s
chars :: [Char]
chars = "**********NiXJo%b"