3.1
[advent18.git] / 3 / s1.icl
diff --git a/3/s1.icl b/3/s1.icl
new file mode 100644 (file)
index 0000000..122f505
--- /dev/null
+++ b/3/s1.icl
@@ -0,0 +1,29 @@
+module s2
+
+import StdEnv
+import Data.Func
+import Data.List
+import Text
+
+getinput :: [Char] *File -> [[Char]]
+getinput a f
+# (ok, c, f) = freadc f
+| not ok = if (a =: []) [] [reverse a]
+| c == '\n' = [reverse a:getinput [] f]
+= getinput [c:a] f
+
+parse :: [Char] -> [(Int, Int)]
+parse c = case split " " (toString c) of
+       [i,_, offset,size]
+               # [offsetx:offsety:_] = split "," offset
+               # offsety = offsety % (0, textSize offsety-2)
+               # [sizex:sizey:_] = split "x" size
+               = [ (x, y)
+                       \\x<-[toInt offsetx+1..toInt offsetx+toInt sizex]
+                       , y<-[toInt offsety+1..toInt offsety+toInt sizey]
+                       ]
+       _ = abort "bork"
+
+Start w
+# (io, w) = stdio w
+= length [c\\c<-group $ sort $ flatten $ map parse $ getinput [] io | length c > 1]