Skip to content

Instantly share code, notes, and snippets.

@zfogg
Last active December 31, 2015 14:49
Show Gist options
  • Save zfogg/8002767 to your computer and use it in GitHub Desktop.
Save zfogg/8002767 to your computer and use it in GitHub Desktop.
/r/dailyprogrammer #145 - easy
import Data.List
merge = zipWith (++)
reflect = map tail . reverse
concat' = intercalate "\n"
triangle n = take n . zipWith replicate [1,2..] . repeat
square n l r = merge (triangle n l) (reflect $ triangle n r)
rectangle n l r = merge (reflect $ square n l r) (square n r l)
tree n = rectangle n ' ' '*' ++ [replicate (n-2) ' ' ++ "==="]
main = mapM_ (putStrLn . concat' . tree) [3,5..15]
@zfogg
Copy link
Author

zfogg commented Mar 21, 2014

 ~
% runhaskell 145e.hs
  *
 ***
*****
 ===
    *
   ***
  *****
 *******
*********
   ===
      *
     ***
    *****
   *******
  *********
 ***********
*************
     ===
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
       ===
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
*********************
         ===
            *
           ***
          *****
         *******
        *********
       ***********
      *************
     ***************
    *****************
   *******************
  *********************
 ***********************
*************************
           ===
              *
             ***
            *****
           *******
          *********
         ***********
        *************
       ***************
      *****************
     *******************
    *********************
   ***********************
  *************************
 ***************************
*****************************
             ===

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment