-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path51.hs
More file actions
35 lines (26 loc) · 940 Bytes
/
51.hs
File metadata and controls
35 lines (26 loc) · 940 Bytes
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
-- this pleases me. i am pleased
import Common
import System.IO.Unsafe
import qualified Data.Map as M
erasures dl d = sequence $
map (\d' -> if d == d' then [Nothing, Just d'] else [Just d']) dl
erasure n = filter hasErasure $ (erasures (digitsBaseN 10 n)) =<< [0..9]
hasErasure [] = False
hasErasure (Nothing:_) = True
hasErasure ((Just _):xs) = hasErasure xs
answer = find8 M.empty primes
incM k = M.alter inc' k
where inc' Nothing = Just 1
inc' (Just j) = Just (j+1)
find8 m (p:ps) = let es = erasure p
(m',ans) = foldIn es m
in case ans of
Nothing -> find8 m' ps
Just j -> j
foldIn [] m = (m, Nothing)
foldIn (k:ks) m = let m' = incM k m
c = m' M.! k
in case c of
8 -> (m', Just k)
_ -> foldIn ks m'
main = print answer