2
[advent18.git] / 2 / s2.icl
1 module s2
2
3 import StdEnv
4 import Data.Func
5 import Data.List
6
7 getinput :: [Char] *File -> [[Char]]
8 getinput a f
9 # (ok, c, f) = freadc f
10 | not ok = if (a =: []) [] [reverse a]
11 | c == '\n' = [reverse a:getinput [] f]
12 = getinput [c:a] f
13
14 Start w
15 # (io, w) = stdio w
16 = map (toString o map fst o filter (uncurry (==)) o zip)
17 $ flatten
18 $ filter (not o isEmpty)
19 $ proc
20 $ getinput [] io
21
22 proc [] = []
23 proc [x:xs] = [[(e, x)\\e<-xs | length [()\\a<-x & b<-e | a<>b] <= 1]:proc xs]