Last active
December 15, 2015 22:18
-
-
Save codepony/5331595 to your computer and use it in GitHub Desktop.
Simple rows script, done as a task for #coders@prooops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- 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