[ create a new paste ] login | about

Link: http://codepad.org/14SQwTia    [ raw code | output | fork ]

Haskell, pasted on Dec 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Main where

listAcc :: (a -> b) -> ([b] -> a -> [b])
listAcc f = \xs x' -> (f x') : xs

-- ***

fillLn aCh fCh n m = air ++ fill ++ air
	where
		fill = replicate m fCh
		air = replicate ((n - m) `div` 2) aCh
				
treeLn = fillLn ' ' '*'		
trunkLn = fillLn ' ' 'x'

treeTri n m = foldr (flip $ listAcc $ treeLn n) [] [1,3..m]
			
xmasTree m = (treeTri m $ m - 4) ++ (drop 2 $ treeTri m $ m - 2) ++ (drop 2 $ treeTri m m) ++ (replicate 2 $ trunkLn m 1)
	
main = putStrLn $ unlines $ xmasTree 13


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
      *      
     ***     
    *****    
   *******   
  *********  
    *****    
   *******   
  *********  
 *********** 
    *****    
   *******   
  *********  
 *********** 
*************
      x      
      x      



Create a new paste based on this one


Comments: