make work for non rectangular fields as well
authorMart Lubbers <mart@martlubbers.net>
Fri, 11 Dec 2020 09:06:24 +0000 (10:06 +0100)
committerMart Lubbers <mart@martlubbers.net>
Fri, 11 Dec 2020 09:06:24 +0000 (10:06 +0100)
11/one.icl

index f96a677..7db34d4 100644 (file)
@@ -35,7 +35,7 @@ numOccupied ls = length [()\\r<-:ls, c<-:r | c == '#']
 
 cell :: (Int Int Int Int {#String} -> Bool) (Int -> Bool) (Int -> Bool) {#String} -> {#String}
 cell lookfun live die ls
-       # ls` = {{step x y\\x<-[0..size ls.[0] - 1]}\\y<-[0..size ls - 1]}
+       # ls` = {{step x y\\x<-[0..size ls.[y] - 1]}\\y<-[0..size ls - 1]}
        = if (and [l==r\\l<-:ls` & r<-:ls]) ls (cell lookfun live die ls`)
 where
        step x y = case ls.[y,x] of
@@ -47,5 +47,5 @@ where
 
 seat :: Int Int {#String} -> Char
 seat x y ls
-       | x < 0 || x >= size ls.[0] || y < 0 || y >= size ls = '-'
+       | y < 0 || y >= size ls || x < 0 || x >= size ls.[y] = '-'
        = ls.[y,x]