Last active
October 22, 2015 00:49
-
-
Save recursivecurry/2cca4c2ba26b1cf9099f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- HACKERRANK: Pentagonal Numbers | |
-- https://www.hackerrank.com/challenges/pentagonal-numbers | |
module Main where | |
import qualified Control.Monad as M | |
import Data.Array | |
pentagonalNumbers :: Array Int Int | |
pentagonalNumbers = listArray (1, 100000) pentagonalNumberList | |
where pentagonalNumberList = let steps = [4, 7..] | |
in 1 : (zipWith (+) steps pentagonalNumberList) | |
solve :: IO () | |
solve = do nStr <- getLine | |
let answer = pentagonalNumbers ! ((read nStr :: Int)) | |
putStrLn $ show answer | |
main :: IO () | |
main = do nStr <- getLine | |
M.replicateM_ (read nStr :: Int) solve |
This file contains hidden or 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
-- HACKERRANK: Pentagonal Numbers | |
-- https://www.hackerrank.com/challenges/pentagonal-numbers | |
module Main where | |
import qualified Control.Monad as M | |
pentagonalNumbers :: [Int] | |
pentagonalNumbers = let steps = [4, 7..] | |
in 1 : (zipWith (+) steps pentagonalNumbers) | |
solve :: IO () | |
solve = do nStr <- getLine | |
let answer = pentagonalNumbers !! ((read nStr :: Int) - 1) | |
putStrLn $ show answer | |
main :: IO () | |
main = do nStr <- getLine | |
M.replicateM_ (read nStr :: Int) solve |
This file contains hidden or 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
Wed Oct 21 00:51 2015 Time and Allocation Profiling Report (Final) | |
first +RTS -p -RTS | |
total time = 34.41 secs (34412 ticks @ 1000 us, 1 processor) | |
total alloc = 924,081,000 bytes (excludes profiling overheads) | |
COST CENTRE MODULE %time %alloc | |
solve.answer Main 98.9 70.7 | |
solve Main 1.0 27.1 | |
pentagonalNumbers Main 0.1 1.3 | |
individual inherited | |
COST CENTRE MODULE no. entries %time %alloc %time %alloc | |
MAIN MAIN 48 0 0.0 0.0 100.0 100.0 | |
main Main 97 0 0.0 0.0 99.9 97.8 | |
solve Main 99 0 1.0 27.1 99.9 97.8 | |
solve.answer Main 100 100000 98.9 70.7 98.9 70.7 | |
CAF Main 95 0 0.0 0.0 0.1 2.2 | |
pentagonalNumbers Main 102 1 0.1 1.3 0.1 2.2 | |
pentagonalNumbers.steps Main 103 1 0.0 0.9 0.0 0.9 | |
solve Main 98 1 0.0 0.0 0.0 0.0 | |
solve.answer Main 101 0 0.0 0.0 0.0 0.0 | |
main Main 96 1 0.0 0.0 0.0 0.0 | |
CAF GHC.Conc.Signal 91 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Encoding 85 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Encoding.Iconv 83 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Handle.FD 75 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Handle.Internals 74 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Handle.Text 73 0 0.0 0.0 0.0 0.0 | |
CAF Text.Read.Lex 65 0 0.0 0.0 0.0 0.0 |
This file contains hidden or 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
-- HACKERRANK: Pentagonal Numbers | |
-- https://www.hackerrank.com/challenges/pentagonal-numbers | |
module Main where | |
pentagonalNumbers :: [Int] | |
pentagonalNumbers = let steps = [4, 7..] | |
in 1 : (zipWith (+) steps pentagonalNumbers) | |
solve :: String -> String | |
solve input = let inputs = lines input | |
answers = map (\line -> show (pentagonalNumbers !! ((read line :: Int) - 1))) inputs | |
output = unlines answers | |
in output | |
main :: IO () | |
main = do getLine | |
interact solve |
This file contains hidden or 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
Wed Oct 21 00:40 2015 Time and Allocation Profiling Report (Final) | |
pentagonal-numbers +RTS -p -RTS | |
total time = 29.62 secs (29620 ticks @ 1000 us, 1 processor) | |
total alloc = 882,503,016 bytes (excludes profiling overheads) | |
COST CENTRE MODULE %time %alloc | |
solve.answers.\ Main 99.2 78.2 | |
solve.inputs Main 0.3 8.7 | |
main Main 0.1 2.8 | |
solve.output Main 0.1 6.8 | |
solve.answers Main 0.1 1.3 | |
pentagonalNumbers Main 0.1 1.4 | |
individual inherited | |
COST CENTRE MODULE no. entries %time %alloc %time %alloc | |
MAIN MAIN 48 0 0.0 0.0 100.0 100.0 | |
main Main 97 0 0.1 2.8 99.9 97.7 | |
solve Main 98 1 0.0 0.0 99.7 95.0 | |
solve.output Main 101 1 0.1 6.8 0.1 6.8 | |
solve.answers Main 100 1 0.1 1.3 99.3 79.5 | |
solve.answers.\ Main 102 100000 99.2 78.2 99.2 78.2 | |
solve.inputs Main 99 1 0.3 8.7 0.3 8.7 | |
CAF Main 95 0 0.0 0.0 0.1 2.3 | |
pentagonalNumbers Main 104 1 0.1 1.4 0.1 2.3 | |
pentagonalNumbers.steps Main 105 1 0.1 0.9 0.1 0.9 | |
solve.answers.\ Main 103 0 0.0 0.0 0.0 0.0 | |
main Main 96 1 0.0 0.0 0.0 0.0 | |
CAF GHC.Conc.Signal 91 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Encoding 85 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Encoding.Iconv 83 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Handle.FD 75 0 0.0 0.0 0.0 0.0 | |
CAF GHC.IO.Handle.Internals 74 0 0.0 0.0 0.0 0.0 | |
CAF Text.Read.Lex 65 0 0.0 0.0 0.0 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment