repositories
/
advent18.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b48d163
)
2.2 improve
author
Mart Lubbers
<mart@martlubbers.net>
Sun, 2 Dec 2018 10:15:40 +0000
(11:15 +0100)
committer
Mart Lubbers
<mart@martlubbers.net>
Sun, 2 Dec 2018 10:15:40 +0000
(11:15 +0100)
2/s2.icl
patch
|
blob
|
history
diff --git
a/2/s2.icl
b/2/s2.icl
index
7c02f7c
..
37febf4
100644
(file)
--- a/
2/s2.icl
+++ b/
2/s2.icl
@@
-1,30
+1,22
@@
module s2
import StdEnv
module s2
import StdEnv
-
import Data.Func
import Data.Func
-import Data.List
-import Data.Tuple
-getinput f
+getinput :: [Char] *File -> [[Char]]
+getinput a f
# (ok, c, f) = freadc f
# (ok, c, f) = freadc f
-| not ok = []
-= [c:getinput f]
-
-split :: [Char] [Char] -> [[Char]]
-split [] [] = []
-split c [] = [reverse c]
-split c ['\n':rest] = [reverse c:split [] rest]
-split c [r:rest] = split [r:c] rest
+| not ok = if (a =: []) [] [reverse a]
+| c == '\n' = [reverse a:getinput [] f]
+= getinput [c:a] f
Start w
# (io, w) = stdio w
Start w
# (io, w) = stdio w
-= map (map fst o filter (uncurry (==)) o zip)
+= map (
toString o
map fst o filter (uncurry (==)) o zip)
$ flatten
$ filter (not o isEmpty)
$ proc
$ flatten
$ filter (not o isEmpty)
$ proc
- $ split []
- $ getinput io
+ $ getinput [] io
proc [] = []
proc [x:xs] = [[(e, x)\\e<-xs | length [()\\a<-x & b<-e | a<>b] <= 1]:proc xs]
proc [] = []
proc [x:xs] = [[(e, x)\\e<-xs | length [()\\a<-x & b<-e | a<>b] <= 1]:proc xs]