summaryrefslogtreecommitdiff
path: root/22-1.hs
blob: f8d7117ba9ee408412d149f89c11440e9b2dbf63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import Data.Bits (xor)
import Data.Function ((&))

mix :: Int -> Int -> Int
mix = xor

prune :: Int -> Int
prune = (`mod` 16777216)

mp :: Int -> Int -> Int
mp cur = prune . mix cur

update :: Int -> Int
update x = mp x (x * 64) & \ y -> mp y (y `div` 32) & \ z -> mp z (z * 2048)

main :: IO ()
main = getContents
  >>= print . sum . map ((!! 2000) . iterate update . read) . lines