{"id":933,"date":"2009-12-12T12:19:32","date_gmt":"2009-12-12T11:19:32","guid":{"rendered":"http:\/\/www.navision-blog.de\/2009\/12\/12\/christmas-tree-in-fsharp\/"},"modified":"2009-12-12T12:54:55","modified_gmt":"2009-12-12T11:54:55","slug":"christmas-tree-in-fsharp","status":"publish","type":"post","link":"http:\/\/www.navision-blog.de\/blog\/2009\/12\/12\/christmas-tree-in-fsharp\/","title":{"rendered":"Christmas tree in F#"},"content":{"rendered":"<p>Today I had way too much time on the train \ud83d\ude09 , so I wrote a little functional christmas tree program:<\/p>\n<div style=\"font-family: consolas; background: white; color: black; font-size: 12pt\">\n<p style=\"margin: 0px\"><span style=\"color: blue\">let<\/span> line width j = <\/p>\n<p style=\"margin: 0px\">&#160; List.init <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; width <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; (<span style=\"color: blue\">fun<\/span> i <span style=\"color: blue\">-&gt;<\/span> <span style=\"color: blue\">if<\/span> abs(width\/2 &#8211; i) &lt;= j <span style=\"color: blue\">then<\/span> <span style=\"color: maroon\">&quot;*&quot;<\/span> <span style=\"color: blue\">else<\/span> <span style=\"color: maroon\">&quot; &quot;<\/span>)<\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\"><span style=\"color: blue\">let<\/span> tree n =<\/p>\n<p style=\"margin: 0px\">&#160; List.init (n\/2) (line n) @&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style=\"color: green\">\/\/ treetop<\/span><\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; List.init 2 (<span style=\"color: blue\">fun<\/span> _ <span style=\"color: blue\">-&gt;<\/span> line n 0) <span style=\"color: green\">\/\/ trunk<\/span><\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\"><span style=\"color: blue\">let<\/span> printTree =<\/p>\n<p style=\"margin: 0px\">&#160; tree &gt;&gt; Seq.iter (Seq.fold (+) <span style=\"color: maroon\">&quot;&quot;<\/span> &gt;&gt; printfn <span style=\"color: maroon\">&quot;%s&quot;<\/span>)<\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\">printTree 11<\/p>\n<p style=\"margin: 0px\">&#160; <\/p>\n<p style=\"margin: 0px\">\n<\/p><\/div>\n<pre>    *     \n   ***    \n  *****\n *******  \n********* \n    *     \n    * <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I had way too much time on the train \ud83d\ude09 , so I wrote a little functional christmas tree program: let line width j = &#160; List.init &#160;&#160;&#160; width &#160;&#160;&#160; (fun i -&gt; if abs(width\/2 &#8211; i) &lt;= j then &quot;*&quot; else &quot; &quot;) &#160; let tree n = &#160; List.init (n\/2) (line n) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[664,555],"_links":{"self":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/933"}],"collection":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/comments?post=933"}],"version-history":[{"count":3,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/933\/revisions"}],"predecessor-version":[{"id":936,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/933\/revisions\/936"}],"wp:attachment":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/media?parent=933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/categories?post=933"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/tags?post=933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}