Skip to content

Commit 8db1c1e

Browse files
committed
Create a more isolated example
1 parent 7f28cf9 commit 8db1c1e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

06.p2x.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Data.List (find)
2+
3+
main :: IO ()
4+
main = print p2
5+
6+
distance :: Int -> Int -> Int
7+
distance rt t = (rt - t) * t
8+
9+
p2 :: Int
10+
p2 = case (first t d, last' t d) of
11+
(Just f, Just l) -> l - f + 1
12+
_ -> 0
13+
where t = 71530
14+
d = 940200
15+
16+
first :: Int -> Int -> Maybe Int
17+
first rt d = find (\t -> (distance rt t) > d) [0..rt]
18+
19+
last' :: Int -> Int -> Maybe Int
20+
last' rt d = find (\t -> (distance rt t) > d) [rt,(rt-1)..0]

0 commit comments

Comments
 (0)