Today I had way too much time on the train 😉 , so I wrote a little functional christmas tree program:
let line width j =
List.init
width
(fun i -> if abs(width/2 – i) <= j then "*" else " ")
let tree n =
List.init (n/2) (line n) @ // treetop
List.init 2 (fun _ -> line n 0) // trunk
let printTree =
tree >> Seq.iter (Seq.fold (+) "" >> printfn "%s")
printTree 11
* *** ***** ******* ********* * *Tags: F#, Functional Programming
Nice one! Schoene Weihnachten!
don
p.s. the “-” in the line
(fun i -> if abs(width/2 – i) <= j then "*" else " ")
is a unicode character needs to be changed to the normal "-". 🙂
Comment by Don Syme — Saturday, 12. December 2009 um 21:28 Uhr
I think I just had a flashback from the early days programming in LOGO.
Comment by Chris Patterson — Wednesday, 16. December 2009 um 5:36 Uhr