Skip to content

Commit 6651b19

Browse files
committed
Add 9 and remove compiled sources
1 parent 5121ade commit 6651b19

File tree

9 files changed

+52
-52
lines changed

9 files changed

+52
-52
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.stack-work/
22
euler.cabal
3-
*~
3+
*~
4+
*.hi
5+
*.o

problem5/problem5

-1.35 MB
Binary file not shown.

problem5/problem5.hi

-1.08 KB
Binary file not shown.

problem5/problem5.o

-6 KB
Binary file not shown.

problem7/p7

-1.99 MB
Binary file not shown.

problem7/problem7.hi

-1.36 KB
Binary file not shown.

problem7/problem7.o

-16.6 KB
Binary file not shown.

problem9/problem8.hs

Lines changed: 0 additions & 51 deletions
This file was deleted.

problem9/problem9.hs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
20+
21+
a^2 + b^2 = c^2
22+
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
23+
24+
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
25+
Find the product abc.
26+
-}
27+
--
28+
isTriplet :: [Int] -> Bool
29+
isTriplet [a,b,c] = (a^2 + b^2 == c^2) && ((a < b) && (b < c))
30+
31+
sumIs1000 :: [Int] -> Bool
32+
sumIs1000 [a,b,c] = a + b + c == 1000
33+
34+
find' = find (isTriplet) [[x,y,z] | x <- [1..1000],
35+
y <- [x..1000],
36+
z <- [y..1000],
37+
x+y+z==1000]
38+
39+
product' [x,y,z] = x*y*z
40+
--
41+
-- TODO Time solution and add produt of resulting tuple below
42+
-- find (isTriplet) [(x,y,z) | x <- [1..1000], y <- [x..1000], z <- [y..1000], x+y+z==1000]
43+
solution = putStrLn $ show $ product' $ fromMaybe [0,0,0] $ find'
44+
45+
main = do
46+
putStrLn "Starting..."
47+
time solution
48+
putStrLn "Done."
49+

0 commit comments

Comments
 (0)