3.2
[advent18.git] / 3 / s1.icl
1 module s1
2
3 import StdEnv
4 import Data.Func
5 import Data.List
6 import Text
7
8 getinput :: [Char] *File -> [[Char]]
9 getinput a f
10 # (ok, c, f) = freadc f
11 | not ok = if (a =: []) [] [reverse a]
12 | c == '\n' = [reverse a:getinput [] f]
13 = getinput [c:a] f
14
15 parse :: [Char] -> [(Int, Int)]
16 parse c = case split " " (toString c) of
17 [i,_, offset,size]
18 # [offsetx:offsety:_] = split "," offset
19 # offsety = offsety % (0, textSize offsety-2)
20 # [sizex:sizey:_] = split "x" size
21 = [ (x, y)
22 \\x<-[toInt offsetx+1..toInt offsetx+toInt sizex]
23 , y<-[toInt offsety+1..toInt offsety+toInt sizey]
24 ]
25 _ = abort "bork"
26
27 Start w
28 # (io, w) = stdio w
29 = length [c\\c<-group $ sort $ flatten $ map parse $ getinput [] io | length c > 1]