Skip to content

Instantly share code, notes, and snippets.

@jroesch
Created August 31, 2012 21:00
Show Gist options
  • Save jroesch/3558924 to your computer and use it in GitHub Desktop.
Save jroesch/3558924 to your computer and use it in GitHub Desktop.
Haskell Version
module Diamond where (diamond)
import Data.List
diamond :: Int -> String
diamond h = concat . intersperse "\n" $ diamondTop ++ diamondBottom
where rows n = map row [((n - x) `div` 2, x) | x <- [1..n], odd x]
diamondTop = rows h
diamondBottom = drop 1 . reverse $ diamondTop
times:: Int -> String -> String
times n = concat . take n . repeat
row :: (Int, Int) -> String
row (s, n) = times s " " ++ times n "*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment