|
module Solver(solve) where |
|
|
|
import Data.List |
|
import Data.List.Split |
|
|
|
solve input = climbers \\ (if null deadend then s else deadend) |
|
where |
|
[rs,s] = splitOn ":" input |
|
climbers = ['A'..'H'] |
|
(cs,ret) = mapAccumL swap climbers (reverse rs) |
|
(Just block) = lookup (head s) $ zip climbers cs |
|
deadend = concat $ filter (elem block) ret |
|
|
|
swap [a,b,c,d,e,f,g,h] '1' = ([b,a,c,d,e,f,g,h],[a,b]) |
|
swap [a,b,c,d,e,f,g,h] '2' = ([a,c,b,d,e,f,g,h],[b,c]) |
|
swap [a,b,c,d,e,f,g,h] '3' = ([a,b,d,c,e,f,g,h],[c,d]) |
|
swap [a,b,c,d,e,f,g,h] '4' = ([a,b,c,e,d,f,g,h],[d,e]) |
|
swap [a,b,c,d,e,f,g,h] '5' = ([a,b,c,d,f,e,g,h],[e,f]) |
|
swap [a,b,c,d,e,f,g,h] '6' = ([a,b,c,d,e,g,f,h],[f,g]) |
|
swap [a,b,c,d,e,f,g,h] '7' = ([a,b,c,d,e,f,h,g],[g,h]) |
|
swap [a,b,c,d,e,f,g,h] '8' = ([h,b,c,d,e,f,g,a],[h,a]) |
|
swap _ _ = error "oops!" |