Skip to content

Instantly share code, notes, and snippets.

@codepony
Last active December 15, 2015 22:18
Show Gist options
  • Save codepony/5331595 to your computer and use it in GitHub Desktop.
Save codepony/5331595 to your computer and use it in GitHub Desktop.
Simple rows script, done as a task for #coders@prooops
{- Simple rows script, done as a task for #coders@prooops
- improved by e (thx. for that) -}
import Control.Applicative -- needed for <$> (equal to mapM)
import Control.Monad
main = do
putStrLn "How many rows do you want to print?"
y <- read <$> getLine :: IO Int
let rowsOut = createAstLst y <$> [1..(2*y-1)]
forM rowsOut putStrLn
createAstLst :: Int -> Int -> String
createAstLst x a
| a < x = take a $ repeat '*'
| a == x = take (2*x-1) $ repeat '*'
| otherwise = take (2*x-a) $ repeat '*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment