Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (42 sloc) 1.235 kB
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
Jump to Line
Something went wrong with that request. Please try again.