-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path014.hs
52 lines (42 loc) · 1.21 KB
/
014.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Maybe
loop :: (Integral a) => a -> [a]
loop 1 = [1]
loop n = n : (loop $ next n)
hasPreviousSmall :: (Integral a) => a -> Bool
hasPreviousSmall n = mod n 6 == 4 && n /= 4
previousSmall :: (Integral a) => a -> a
previousSmall n = quot (n-1) 3
allPrevious :: (Integral a) => a -> [a]
allPrevious n =
if (hasPreviousSmall n)
then [n * 2, previousSmall n]
else [n * 2]
listPrevious :: (Integral a) => [a] -> [a]
listPrevious [] = []
listPrevious (x:xs) = allPrevious x ++ listPrevious xs
subtractList :: (Integral a) => Set.Set a -> [a] -> Set.Set a
subtractList xs ys = Set.difference xs (Set.fromList ys)
removePrevious :: (Integral a) => (Set.Set a, [a]) -> (Set.Set a, [a])
removePrevious (xs, ys) = (subtractList xs prev, filter f prev)
where
prev = listPrevious ys
f = (<= 500)
next :: (Integral a) => a -> a
next n =
if mod n 2 == 0
then quot n 2
else 3 * n + 1
-- answer must be > N/2
-- answer must not be congruent to 2, 4, 5 mod 6
-- answer must not be congruent to 1 mod 6 unless > 750000
testMap =
[(1,1)
,(2,2)
,(3,8)
,(4,3)
,(5,6)
]
newLoop :: (Integral a) => a -> [a]
newLoop n = takeWhile (>=n) $ loop n