Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.03 KB

Fur tree (exercise).md

File metadata and controls

57 lines (42 loc) · 1.03 KB

title: The "Fur tree" exercise categories: puzzle ...

The "Fur tree" exercise

There is a programming exercise I like: "The fur tree". The task is pretty simple. You just need to grow a tree with a defined height (number of levels). Your tree should look like this (that one has height "5"):

    *
   ***
  *****
 *******
*********

Here is a small collection of thees grown by me :)

Haskell

import Data.Char (isSpace)
import Data.List (takeWhile)

main :: IO ()
main = putStr $ pine 10
  where
    pine =
      unlines
      . takeWhile (isSpace . head)
      . iterate (tail . (++ "**"))
      . (++ "*")
      . flip replicate ' '

Python

# one can rewrite this code as one-liner :)

def pine(n):
    return '\n'.join(
        (' ' * (n - x)) + ('*' * (x * 2 - 1))
        for x in range(1, n + 1)
    )

print(pine((10)))
dc -e "[32P1-d0!=b]sb[42P1-d0!=s]ss[lilbxln+li-2*1-lsx]sr[li1-silrx10Pli1!=m]sm 10 1+snlnsilmx"