fork download
  1. import System.IO
  2. import System.Random
  3. import Control.Monad
  4. import Data.List
  5. import Data.Maybe
  6.  
  7. main :: IO ()
  8. main = hSetEncoding stdout utf8 >> mapM_ (christmasTree >=> putStrLn) [1..7]
  9.  
  10. ornaments :: [Char]
  11. ornaments = "*NiXJo%b"
  12.  
  13. christmasTree :: Int -> IO String
  14. christmasTree h = do
  15. is <- mapM (flip replicateM (rollIkasamaDice dist)) ws
  16. let body = ["☆"] ++ map (map (ornaments !!)) is ++ ["||"]
  17. indent = reverse $ map spacer $ [h - 1] ++ map (`div` 2) ws ++ [h - 1]
  18. return $ unlines $ zipWith (++) indent body
  19. where
  20. dist = 30 : replicate (length ornaments - 1) 1
  21. ws = [2, 4 .. (h - 1) * 2]
  22. spacer = flip replicate ' '
  23.  
  24. rollIkasamaDice :: [Double] -> IO Int
  25. rollIkasamaDice dist = do
  26. r <- getStdRandom (randomR (0, 1)) :: IO Double
  27. return $ snd $ fromJust $ find ((r <=) . fst) dice
  28. where
  29. thr = scanl1 (+) $ map . flip (/) =<< sum $ dist
  30. dice = zip thr [0..] :: [(Double, Int)]
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:2:8:
    Could not find module `System.Random'
    Use -v to see a list of the files searched for.
stdout
Standard output is empty