Skip to content

Commit c1003ac

Browse files
committed
Add 0 padding for directories
1 parent 6651b19 commit c1003ac

File tree

11 files changed

+40
-0
lines changed

11 files changed

+40
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

problem010/problem10.hs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Data.List
2+
import Data.Maybe
3+
import Text.Printf
4+
import Control.Exception
5+
import System.CPUTime
6+
import System.Environment
7+
8+
main :: IO ()
9+
time :: IO t -> IO t
10+
time a = do
11+
start <- getCPUTime
12+
v <- a
13+
end <- getCPUTime
14+
let diff = (fromIntegral (end - start)) / (10^12)
15+
printf "Computation time: %0.3f sec\n" (diff :: Double)
16+
return v
17+
18+
{-
19+
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
20+
21+
Find the sum of all the primes below two million.
22+
-}
23+
--
24+
prime :: Int -> Bool
25+
prime n
26+
| even n = False
27+
| otherwise = Nothing == (find (==0) $ map (mod n) [(n-2),(n-4)..3])
28+
29+
sum' :: [Integer] -> Int
30+
sum' = foldl (+) 0
31+
--
32+
-- TODO Time solution and add produt of resulting tuple below
33+
-- find (isTriplet) [(x,y,z) | x <- [1..1000], y <- [x..1000], z <- [y..1000], x+y+z==1000]
34+
solution = putStrLn $ show $ sum' [x.. | x <- prime x]
35+
36+
main = do
37+
putStrLn "Starting..."
38+
time solution
39+
putStrLn "Done."
40+

0 commit comments

Comments
 (0)