Compare commits

..

No commits in common. "3bb59888cdf7858e170bc918563762231771fa56" and "956228b4871e1fb1a68bcd6bc3913925f925e3f5" have entirely different histories.

7 changed files with 18 additions and 629 deletions

2
.gitignore vendored
View file

@ -1,3 +1 @@
example* example*
*.hi
*.o

View file

@ -25,10 +25,5 @@ https://adventofcode.com/2020/
|17 | | `**` | | |17 | | `**` | |
|18 | | `**` | | |18 | | `**` | |
|19 | | `**` | | |19 | | `**` | |
|20 | | | |
|21 | | | |
|22 | | | |
|23 | | | |
|24 | | `**` | |
`test.sh` can be used to run all solutions and automatically compares them to (my) puzzle inputs and the expected outputs. `test.sh` can be used to run all solutions and automatically compares them to (my) puzzle inputs and the expected outputs.

View file

@ -1,28 +0,0 @@
module Conway
( Index(..)
, update
)
where
import Data.List
import qualified Data.Vector.Sized as V
import Data.Map (Map)
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S
class Index i where
neighbours :: i -> [i]
addIndex :: i -> i -> i
counts :: Ord a => [a] -> Map a Int
counts = M.fromList . map (\xs -> (head xs, length xs)) . group . sort
neighbourCounts :: (Index i, Ord i) => Set i -> Map i Int
neighbourCounts = counts . concatMap neighbours . S.elems
update :: (Index i, Ord i) => (Int -> Bool) -> (Int -> Bool) -> Set i -> Set i
update create destroy old = M.keysSet $ M.filterWithKey shouldLive $ M.fromSet (flip (M.findWithDefault 0) nCounts) indices
where nCounts = neighbourCounts old
indices = S.union old $ M.keysSet nCounts
shouldLive ix n = if S.notMember ix old then create n else not $ destroy n

View file

@ -1,2 +0,0 @@
512
4120

View file

@ -1,558 +0,0 @@
nwwnwnwnwsenwnwenwenwnwnwnwnwwneswwnw
nenewsesweeeeeeeeeeeeneeee
swswswseseneswseswnwseseseseswnewseswsesw
swseseseeswsesesesesesesesesesenw
wnenenwnenenenenenenesenwnenesenenenene
esesenwseewseseseseseeseseeesweseese
eseeeneeeeeeeeeweeeswewe
seeseeswnweeneswwswneweeseenwsee
nenwneswneneeenenewneneeneneswnwnene
enwnwwnewnwnewwsewnwnwnwnwswnwewnw
neneneneswnenenwnwnwnenene
seseswesenwnweenwseseseeneeesewsesw
eeseswsenweneeeswneseenwseeewse
nenwneseeeneneene
eeneswnweseeeeeeneenwee
nwnenenesewnwseswwenwnwnwnwnwnwswwnwnw
swwswwwnwswwwswwwwwwewewsww
wwsewnewwwwwwwswwwwwwww
nwwnwwnwswneswwsewwnewsesenewnwe
eneeswseeeeeeesweenewewene
swewswnwnwswwwswsewwwwwswswwsww
swwneseseneswseseweswnweswwswesese
eneneneeeneneeeesweeewenenee
wseeseseseseseeseeseseseseewsesene
sesenwswswnwswseeswsweswnwswwswswnwse
eeenwseeenweeseeeeeseeeswsee
eseewseneswseeewsewswnwnweenee
seeeseesenwseseeeeweseesesesee
neseenwneneneneneeewneweneswnenww
wnewseswswswseswseesewseswneswswseswsw
wswenwsenenweseswnwewnwe
swwswseswnwswnenesesewenesenesewneswsw
nwnenwnewnwnwnwnesenwnwswnwnenwnwsenwnw
nwnwnwenwnwnwnwnwnwswnwnwnw
eeeeseseswseseeeeeneswseeeneee
ewwwwwsewwnewwwswwwwwwsww
wswwwwwnwseewwnwenwnwnwnwnwne
wwwenwwnewswewwwnwwswwwww
senwnwseesenenwnwesw
sewswwwwwwwwwwwwwwsenwwnew
neneeeewneeeneeeseeneeeenee
neeeeeseeeseswenweseeeenwee
eeeeeeneeneneswweeeeeene
seswwswswneswswswswswswswswswsw
nenwsenenesenenwnwnenenwneswsewsenewnenene
seswnwsenwswswswswswswwseswswswnewswsww
senenwnenenenenenewneenenenwnwnewnenwnwnw
wnwnwnwnwnwnwwnwnwenwwswnwnwnwnwnwnw
ewswwwswswwswswwswswsw
nwnwnwnwnwnwnwsenwnwnwnwnwnwnwnwnew
nenenenenenenenenenwnenenenenenwswswnenene
nwnwswwseneseswweswswswswswwnewewe
eneeeswseswneswenewnwwee
neswnwnenenwesewnesenwnwnwnwswneneneenw
seseswesesesesewneswsesesesesesewsese
wwwwswwsewwwswswnenewwww
wwwwsewwswsewnenwww
sewswseswseswseswswnwswnwswswwnwwswnww
esenwnwenwnwnwwnwnenwnenewnenwnwnwne
nwnwwnenwseenenwnwnwewnwnwnwnwnwnwnwne
swnwnwnwnwnwnwnwwnwnwswwwenwnwnesenw
swswswswnwseswswswswwswswneswswswswwesw
wsewenenwswnwnweewswwneswenesww
swwwswwswwswswnewswwsewwwwww
nweesweeeewseneeenee
wwwwnewsewwwswewwwwwnwww
seseseseseswsesewnenwswnwswswswnwswsesese
swseswseseswswsewseswswswneneswnwesesese
wneswnwneneneneseneneneneneneneneneenenwnw
neseseesenwseseeseseswsenwseesewsee
wwwnewewwwwwwwswwwwwswe
weeenwweneswneseneeeseeneneee
nwnwseseweswswswswseswseswneseswswsenese
seswenewneswseewnwww
eseswneseswseswswwnwse
nesweeneneseweeseeeeweenwwee
seewseenwwnesenesewswwwwnwwnwseene
nwnwwnwnwnwnwswwnwnwnwnwnenwnwnwnwesw
wnwwwnwnwnewnwnwnewnenwnwsesewsesw
nwswswsesweswwewwswnwwsewswnewnesw
swseewseseseneeseseneeeseseseseew
seswswseseseneswsewseseneswseswswwswsw
wwwnwwwewnwwwwwswwwwwnww
nenwnenewnenenenwwnwneneeneneenenenenw
nenwnwnenenwnwneneswnwswnenenenenenwnwnwne
nwnenenwneswneneeswnwnenewenwnwneene
nwewnwnwseenesenenwwswnenenwnwnenwnw
wnwwnwsewnwnewwwwewwwwwnwww
wwwewnewwwwwewnwswwnwwwwwse
senweesweseseseeeseeswenweeeese
swnenenwnwnenwnwnwnwswnwnwnenwnwnwnwnenw
nwenwnewwnwnwenwnw
swnwnenwswneneeneeneee
seseseswseseseseseswseneswswwesesesesese
seseseesenwsesenweseeseweeseseseswse
eeneeeeeeseeseseseswseeee
swswwswseneseseswseswseswnwwswswnwswsene
wesewwewwwwwneswswnw
nweewnwwsenwnwnwwnwwnwswwnwswnenw
eeeweeewseseeseseeeeesenwne
wsenewwwwwwwwnwwsewwwnwne
seewswnwnweeenesweseswseneesewe
swnewnewseneswweewenwwweswswnw
swweswnwswwnenwwswwwsenewnenewew
nwnwwwewnwsesewnwsww
neweswwnwnewswnwwewswneseewnwnw
swnwnwnwsewnenwnwnewsenwnwew
neseesesesesesesesesesesesesesewwsesewne
swwwnewnweeneswswseeswenwseswneswne
swnewsesenenwswsewsewnwwewnwwnwe
neseewseseseeswswsesenesenwsesenwseswse
swswswswswwswswseswswswswneswsweswsww
swwsweneswseseseneesesenwnwseeesesee
sesesesesenwseseseswnwswseseseesesesesesw
wwenwwsenwwwenenw
nenenwnenenenenenenesenenenenenenenene
swseseseseenesesenwsese
swsweswsesesesesesesesesesenwwse
seeeswswnweseneneswwnwsweneweenee
nenenenwnenenwnwnenwsenwnenenenenwsww
enewsesewseswsesewseeweseneenenesee
eseswswseneswwswnwseseseewswwwneseswe
eeeneseseeseeseweeeeewese
nwswwwwwwnwnwwnwewwwnwwwnwnwe
swswseswsesweswneswwswwnwswnweneswswne
sweeeneeeeneeeesweeeneneee
neneeneneneneswnenenewneneneeneeneene
swwnwnwnwwnwnwnwnwnwsenwnwnwnewsenwnw
eeeeenwseeseseeewseseseswseeee
wwnwwwswwwnwwwnenwewnwnwwwww
enenwseneneneneneeneneneeeneene
eseswwswwsewswswswwwswwwnwwwnewne
eeeneswnewswsesenwwsenenesesenwee
senweseeseswseseseseseseseseseseseese
swneswwwswswswswwwwswwswswseswswnwsw
swswswsewswneswwswswwwswswnwwwwesw
eweewnesenwnwwswswnweseseeneese
swsenewnewneneneseneneneneneenenenewene
nwnwweswwwswwwwnwwswwweswesw
neneneswwnweeeweswneeswneswwsenwnww
nwswsweswnwnesenwnwwswneeswswwesese
nenwnesesenewesewnwnenenwwsweeww
swswswswswswwswnwnesweswswswesw
wwwnwenwnwnwewwwnweswenwnwneew
nwwwnwnwnwnwnwwwsenesenwnwnwnwwnwwnwnw
eneneseseeesewenwsesesesweswsesese
seswwswseseseseswswseneswseswswsesw
swewswswwsweswswswswswswswwswswswsww
wnewneenesenenenwnewnenwnenenesenwnenenw
seswseseswwwsesenesesesewseewseswnene
eeneswneneneeneneeneneeneenene
swswswswswswwswswwesw
wwwswswswswswewswnwswwwewwsenwsw
eseeeesenweeeeesewseeeseee
swswwswwwswswwneswsweswswswswswswsww
seseenwseseswswsesesesw
newsweeewnwenewnesewsewnewnene
nwnwnwnwnwnwnwswnwnwsenwnwwnwnwnwnwne
sesesesesenesesesesewswseseseseswsesese
seseseseseseeseswsesesesewsesese
wwseswnwseswswnewwswwnwswwswwew
sewweswseseseseseseswseseseweneseswsw
nwnweneewnwnenwswswnwnenwneswnwwenenw
swnwnwnenwsenwnwsenenwnenenweswswnwnenee
seswseneneswsewewwnewnewwnwwwnesw
seswswsenwswswswswswswseseswseswsenesesewsw
senwseeseneseseseewseseseswweesesew
seweswsesesesewnwnweseseeswseneseswse
eeseeseeeeweeesee
swwswwnwwwnwwwwwnewsewwewwswe
nesenwneswenenenwnwwnenenwsenenesesenew
wenwswseseseseswseeseswwneseesenwse
nwneenwneseswenewsweseseneswenwee
seeseseseseneseseseseseseenwsesesesesew
wnenewneneneeenwenweneswswswseswnwse
wwwswwsweswswwwswswswsww
eeeweeseseeeeeeeenweeene
eswwwswsewnwwswnwewwswwwwwwsw
enenenwneneeeneweneeneeneseswee
wswwsesweswwenwewwswnenwnwswnewew
seseenwwwseswswneswneswsewneseeswnee
swneeeeneneswnwesweeeneeenwene
neneswnwwseeswseswseneesenwswswwnwswese
seseseswseseseseseseenwsenwseenewnwsewe
wneswweseswseswsesesesesesesese
seseeeseswseseseseseseseseseesenw
nwnwsenwsenweeseewesesweseswseswe
wneweswwwwwwwwwwwwwswwwsw
ewwswseesenweenwnwneneeese
sesesesesesesesesewseneesesese
swswswswnwewswwswswswswswswsw
nenenewwnesewneneneeneeneneeeeenee
senenwewnenenenenenenenenenenenwnwnenesw
swwsewswwswenwswnwsweswswewswnenw
swswswwnwswswswwswwwswwwswwswesw
seweeeeneeweeswseewnweeeeese
nwneeseeweenwswswseeeenwseenesw
wwnenesenwnwsenwnwnwnenwwenwnwnenene
eseeeenweneswesesw
swsenwwwnenwwswsenenenewwneswnweww
newnwnwnwnwnenenwsenenwnenwnenwnenwsewnw
eeseneenwsweeneenwnwnwnwsewnesese
eneseneneenweseneweneeeesewnenee
wswswswneswswswseswswswswswswswswswswsw
swswswenwneswswwswswswswseswswswnwswse
wesewseseeseseeeeseeseseeeesee
senwswsesesesweweenewswswswnenwsenwese
eseeeeeeeeewneeseeeewseeese
wwwwewswwwnewwwwwwswnwww
nwseseseswseseseseseswnwseseswswsesesesene
enweenewneseeewneeseeenwesenew
nenenewenweswnwneeneweseseneswneee
ewwwnwwwwwsewwnwwwwnwwwsww
neneneseswnewnenwnwneneswnweswwsenwswne
nwnwnwswnwwwnwnwwswnwwnwnwnewwwe
nenenewneewneeseseneenenenenenenw
nwnwsenwwwnwenwnenwnwwwsewwwnwsw
nwnwwwnwenwwwnwsewnwnwwnwnwnwnwnww
sewswswswswseswswseseswswswseswswswsene
wsenwnweswnwswewswnwnwewwsenwwnwww
swswneswneswwswwwwswswnewsw
wnenwnwnweneneswwnwenwneneneseseswwnw
nwnwsenwnwwnwsweswnwenwwnwwnwwnww
sweeeeneseeesewenweesweeee
nesewneneneneswneenewnesewsenenenewne
ewwwwwwenewenwwwwsweseww
nwewnwwswwwnwnwsewwwnwnwwwwwnw
seseeeneswsewseeseeeseneswsesenenw
senweswnwnenenenwnwswnwnenenw
nwswnwswnwnwnwwnwwnwwnewnewwnw
swswseweswwswswswneswewwwwswwsww
eeeneneeeeswnenwneesweeneeeeee
swswswswsweseeseswsewswswnwseswswseswsw
neseseseseseseseseweswseswsewswsese
nwwseswwnwnwwnenwwnwswwenwwne
ewsweseneeewneeeeweeeseneeese
seeswneseneenwnwewswnweseseswnwesese
eswswseswswswseseseswswnwsw
nwesesenweseeeseseseeseseswseswee
nwnwswnwwnenewnwnenwswnwswnwwwwnwnwnw
enweeswneeswweenwewseeseswsese
wwnwswswwwwwwwswwwneswwseswwe
nweeeeeeeeeeseeeeeeeesw
eseenwsenwseeseseenwwseswsese
neeeeseeseswewsenweseseeeeseesee
wwswswneseswswesweswswswnwseswswswesw
neeneneeeeeweeeeeneswwe
seswseseseseswseswswswneseseswsese
newwnwnwswnwwesewnenwwweswwwnw
nenwneneneneneneswnewesee
wswwwwwwwwswswswwwnewwwsw
nwswswseseswewseseswseswswswswsesesw
eeeeseseswsesesesesenesewewsesesenw
nwnenwseswnwnwnenenwnwewnwnenwseenwwnw
seswwwwwswseneenwneswswnenwsewswe
seswsenwseswseseseseeseseswneswwswwsese
swneneneneesenwnenwnenenenewseswnenenee
nwswnwwnwnwnwswnwsenesenenwnwnwnwnenwsenw
nenenwnwwnwnwnwnwnenwnwnwnwenwnwnwnwsw
neswwsewneneneeneneneeneeneneenee
seseneseswswswnwswswswswseswswswswwesw
nwnwnwenwnwnwnwswswenwnesenwnwnwneneswnw
enweeneeesweeeneeeeeeeee
seseseneseseswsesesesesewseseswsesenesese
seseswswnwneswswwswswseswseswswseneswswesw
seseseseseseswseeeeeeeeseseenw
eseenweseeenwesweeeeeeeese
seewneeneeeeneenesweenenwneeene
nenwnweenenwswsewnwwwsewnweneewnw
eseseseseswseenwesesesenwseseesesesese
wswswswneswswsweneswwswwswnwswsw
wwwwwwswwwwswwseenewsewnwnw
seseeesweenwseseswseeseeseesesesenwse
nenwnwnwneswnenenwswseeeswswneneneseww
swwwswsewwswswwneesenwswsewnenww
wnwseseseseseenwsewneenweseseeswsw
enwnwnwnesenwnwwsewwsesewnewwwswe
nwnwwnwsenwwnwnwwewnw
seseneswseswwseswswseseswswseseseseswsw
nwnenenwnwnwnwnwnenenwnwnwnwwsenenwnwnw
weseeneneneneneswneeenenesenewenewe
wwwwnwnwnwnwenw
nwnwsenwseseseswsesenwsesweswswneseeswe
seseswsewseseneesesenwnwse
wswwseswswwwswswswwwswnwwwwwene
eneswnwwnenwwenweewsweeswnwnwswne
wwwwnwnwsweswwenwnweswnwnwwnwe
nwseswswnewsesewnweswneseenesenewew
swnesweewwswwwswswnwswsewwwwnw
neeswneswnwsesenewneneswnwnewnwnenwne
swswswswseswswswswneseswseswswswsewsesw
swseneswswswneswseseswswswseseseswswsese
swswswswswwnwswnesweseneseswnweswswsesw
wnwwwwnewsenwswsenwwwwwnww
seseneswswswswsenwswswseswseswswwsweswswse
enwweeeseeeseneeneeeneneenee
seeeswseeesenwesesewseseeseesee
sewwnwwwwwswswnwswseewwewswwnew
swwsweneneswswwswneswwwwswseswswswsw
nwswseseseseseseseseseseseneseswsesesesese
wswwwnwnwwswwsesesweneneneswwswwsww
newswwswsewwnenwwweseswsewnwswsenenw
swswswseseseseswseswnw
nenenenenweswneneneneneewneenenenesene
seeseneswseseseseseswsesewswswswswsese
ewwwnwswwnwwwnwenwsenwewwsesenw
nwswnenwnwnwnwnwnweenwnwswnewnwnenesenw
nwwswwwwswwswnesewwwswwwwwww
sewwswwnwwwwwwwewwwwwwwnew
wswnwwwwnesewnewwnewwwswseew
nwnewwewneswnwwsenwwesenwwnww
neneneweesweeneneenenenese
wnwwsewwwnwwwwnwww
nwswenwnwswwnwnwwnwenwnwnwnwwsewww
seseswesenwseseeesenwseseeeseswsew
enweeeseenesewsenesesewseeesew
ewnwnwseneneneswneneneneswneeneswnenee
seseseseseseewseseseseeneseseseesese
nenwswsenenenewwnwnesenenenwnenwneese
swenwnwwswwwswswwesenwwnewswsw
seewswseeesenweeweeneneewneeww
eseseseesenwseeseseseesesesewnwsee
neseneeseswseseswseseseese
swnewnwsenwnenwneenesee
nwnwnwnwnwnwnwnwnwnenwsenwnwnw
nwwseeswenwnenwwwswsenewnweewesw
swswswwswswswswswswswswwswwnwwneeswwsw
nwnwnwsenwnwnesewnwswenwnwnwwnwnwwnw
nenwnwseeneneswswswsese
eeneseneeneneenenwnesweeeeneenw
neneneswnwswneeeneeeneneneneneneenwne
nesweeeneneeeweweeneeneenene
eseneneeenwsenewnenenewseswnenenenwne
swnenwneenenenenenesenwenewnenenenenene
wwwnwnwwenwwwnwwsewwnwwnwnwnww
ewwwwnwwwewsewnewnwwswsewwnww
esenenwseeseseseseseswsewswe
weswswswswwswnewwwwwwwesewswswnw
wwswwswsweneewswswnwnewswwwwwww
nwneneneneneneeneneneneswwneneenenenese
neenwnenenwnwswnwnenenenwseneswnwswswnww
nwnwewnwnwwewwenwwswsesenewww
wwwwwsewwwwwwwwwwwwwne
wseseseseseseswseseseesesesese
nwnwswwnenenenenwnenenwnenwnesenwnwnwnenw
nwsesenwwwnwnwnwnwnwnwwwnwnwnwnwnww
nwwwwwnwwwnwswwnwewww
eseneeseeseseeenwseeseeneseswseesw
swsewswswseswswneswswwswswnwswsweswsw
wwnwwwswwnwwnewsewwwnwne
swswswsenwswswswwswswswswswsesweswswsw
swseswneswnwswswsweseswnewsweneswnwswsw
seeseseeeweewseseneseewseseee
eeswneeeneeeneenenenw
nwnwnwnwnwnwnenwnewsenwnwnwnwnwsesenwnenw
nesenenwswneeswseseneswswnwnwswnenwswnew
wwnwnwwwswwwsenwwwwwnwewwswne
nwnwnenwnwnwswnwsesewnwsenenwswnenwnenwnw
nesesewewneswswsenwnwseenwwnesweenwe
seswweweseeeeeenwneeswenesewe
sewwswwnwswswwswswswneswswwweswswwsw
seseneeseseseseeseswseseesenwesesese
nwnenwnwenwwnwnwnwnwnwnwwnwnwnwsewe
wwnweswsenewsweswwswswwnwwswwww
nenwnwneneneneneneswnenenewnenwnenesenenene
swnwnenwswenwneswnwnwwnwnwseneenwwnesw
sesesweswnwnwswsesesweswseswsewswswsw
enenwneneeeeneeneseeneneneeneswnwe
wnewwwwwwwsewswwnewwsewwnw
seswnesesesenesesenesesewswsesesewsese
wwwsewwneswwswwnewne
sesesesesesesesesesesesenwswseneswseese
eneneneneneseenenenwenwswneneneswnee
wnwwwsesenwnwnwnewwnwnenww
nwswnwwseewwwwwewswenwswnwswsw
swsesesenwseswswseswswsesenwswseswsesw
wwwwnewwswswwwwwswwww
sesesesesesewsesesesewneseneesesewse
esweeeenweeeeeeeeeeeee
wsewesesewseenwnwneeswswnesenesee
wswwnwweswswswwswswswswsenwswswsw
swnenwswnwsweseswenwnwwweswweewse
swnenwwwneswwwswwneswseswwswwsesw
neeeeneenwseeseeeenenewewee
nwnwnwnwnwnenwswnwnenwnwnwnwwnwnwenwnwnw
swneswswswseswswenwneseswswseswswswswsw
seeseseneneswsesesewneeseeeswseseeswne
nwnwnewsenwenwswnenwnwnwnenwnenenenwe
swneswneneneenwneneneswenenenwnenwnene
neswseswnwnenwswnenwnewneswwswnwnwnenwnw
neneneseswneseenwnenenewwwneneneenwne
newsweswnwswneswsweswwwswswwsewsww
ewenweseeeweeneeeneneseswee
wswseswswnenenewswswsewswswewseew
nweneeenwwswsweeeseneseneeewne
senwwsweswnwswswsenwsewseswnwneeswe
swseswwewwnenewswswwnwwswwswsenew
eenenenenenenwnenwswswnwsweeeenee
neneneeneneeneneeneneneneesewneene
swnwwnwswswweswswswswswswswwseswswwsw
wwwnwnwnwwwwwswwwwnwnwnwsenwwne
wwswnenwwnenwwwewwwwwesesew
eeeeewseeseneseseweseeeeese
nwseeeseseeneeeeseeseeseeewe
eswneeneeeneneweseeneeneneeee
wnwswswwswsesweswswswswnwswswswwswsw
enwneneneswneneneneneenwsenenwnesenewsw
swnwnwwswnwwnwwwwnwnwwwsenenenww
wnweseswnwnwwnwwswnwnwnweeenwenwse
nwnwswnwswnenwnenwnenwenwnwnenwnwnenwnw
seseeseseseneseenwswneseseswnwsweneswwe
swwwwwwnwnwwwnwswnwwwnewewwne
eneneneswneneneneenenwnenenene
nesewsesewneswnwwwnwwwwwwnewwnenw
enenenwnenenenenenenesenenee
seswseswswswesenwseseswnenwswneswswswsw
nenenenenenewwneneenenenenenenesenenene
swneswnewswwwwswswswwwswswseswwsw
nwnwewnwnwseeneswwswnwnwwnwwwnwnwnww
eeeswnweeeweweweee
enwwnwwenwwsww
wneswsewswwwwwswwswwwswwww
swwwwewnwwweweswewwenwww
wwseswenewwwwwwwwwwsewnwwww
nwsewseseneswesweseswnwwswnew
swneseswswswswswswswswseswswswswswswsene
nwneneneneswneneswnenenewnenenenwswenene
wwswwewswswswswswwwswnwwwwseswsw
nweeseeeeseseeseesweseenwsesene
wneswswneneneenenenesesenewenww
seswneeneenewseeneenenenweneeene
neswewsewnwnenwnwnenwnwesewneneeswe
eeeeenwseeseseeeseeee
ewnwseeseseseeesenweseneseseseseese
swwneswewwnwwewwwwsewswnewww
swwswnenwesewneseenwswenewnwenww
nwnwwnwnwnwwwnenwnenwwnwsewnwnwnwsw
swnwswswswwswwswwnweswswswwswswswwe
wnwneeeeneneeesesweeeeeenee
ewnwneenwnenwnwnenenenwneneneneswneswnene
wwwenwswwnewwwweswwwww
swseenwwswswnwnwswsewseswswseneeesw
swneseseswswswseseseswswseseseswsw
neneneenwneneswwnwnenwnesewnenewnwnee
swnwswswseswseseswseswswswswnwseswswsesese
wswwswwwwswswwswsweswwswswnwww
nwnwwneseseneenenenenenwwneswnwsenewne
wnwsenwwwwwnwwwneswwwwwnwnwnwe
swswseswneseswswsewswswswswswswswseswnee
swsesewswnewnenwsenwneswneswwwswwsw
swseswswswsesesesewswseeseswseeswsenwsw
seswswwseeswswenwswseswenwswwswsesw
neneneneneneneneneneneswneweneneneneene
swsweneenwnwsweeeeenweeeeee
neswnesenwwswwnweeswsweswnesewsww
nwesewnwseewswswnwwswneeenw
eeseenesewsweseswnweseesenwnesesee
wneswswswnwswweswnwwsweswnweswswesew
senwnenenenenenenewnewnenenwnesenwneswse
nesenweswnwnenwenenwnwnwswswnwnwnwsenene
seswsweswswwwswwswwwwwwwswnewsw
enwwwswswswswswswswswwswwseswswnenwswsw
nwewwenwwwewwswswwwwwwww
sewseneswesweweeweenwneeesee
nwnwwwewnwwnwnww
seseseeenwswwenwswswseenwseseeseeee
seseswseesenesenwsesenwsesewsesesesesese
wwswwsesewswswwswwwenewswwswsenene
nenwnwesenwnweswnwnwnwwnwnwnwswnwsee
seswswswswswseseseenesewwsesenwsesesenw
wswsweswsenwwwwswewneswsew
swneneweswenwswswseswswseswnwsesewswesw
nwnenwsweesenwwseswenwwwseswwswnw
wwnwenwnwnwnwswnwnwnwnwwnwnwnwwnw
swswswneneenwnenwnwnwsenwenwnwwwnweenw
nwnwwnenwenwswnwnwnwswwenwnwneneswnwnwsw
enwnweewenesesweeneneeeeeene
nwenwweeeeeenwneeeswseeeswse
nwseneeneneeeeneeeneeeneenenenesw
wwneswswswewswsesenewwseswswnwswsw
swseswswswswseswsesweswswswswswnwswswswnw
nwweswwseseeseseneswnesenweseesenewe
wnenwnwnwnwnwwnwnwnwsesenwnwnwnewnwsenwnw
nenenenwnwsenenwnwnwnwnenwnwnwnwnwnwnwsw
ewsweenwnweneeeseneweseeesew
wnwnwnwswswswswswseeswswwswswseswswe
nwwswnwneeeeswewwnwswnwenwswswenwnw
swswswneswsewswswnewne
swsesesenesewswseseseseswseswsesesesese
nenewneneneneneneneeeneweneneeenese
wwwwnwwwwwwwwwwwwsewnew
wwswswnwswwweswwwwwswwwwsww
nwnwnwnwnwnwsenwenenwneswnwsenwnwnenwnwnwse
neneneneneneenenwneseneeenee
eeneeeeneenwswnesenenweeeeenesw
swnenenwseewnesweseseenwsesewseswnwse
seseswnwsesesweseneswsesesenwseseseseswse
nesenenwnwnwnwnenenwnewnwnwnwnwnwnwnwne
nenwnwwswnenwenwsenwnwsewnwnwnwwww
neswswseswseswswsesenwswswseswnwsweswswne
nweneseswnwnwnewnwneenenewnwnwnenwnenenw
eeseneeswswnweswseesesenwnesesesesee
eseseswswswswneswwswswneseswswwswwsw
seseseneswewsesesesesenesesesesesesesese
swsweewnwsewwenwsenenewnwsenenee
wnwwwnwnwswwwenwseeenwnew
swnenwneseseswswswseswswseeswnwseswswswswe
nwnenwwwnenwwsenwnwsenenwnwnenwnwnwnwse
swnwnwnwnenenenwnwnwnwseneenewnwnwnwnwnene
wnwewnwwswwwnwnewwwnwnwwswwwnww
nwsenenwnenwnenenwnenwnewnwseswenenwnwne
neneseeeneneenewneneneneswnene
sweeenweeseweseseesewseeee
nwswseneeeneenwneneeeswseneswenwene
nwnwwnwnenwnwnwwnwnwswwwnw
wwnwwnwwwnwwnwwwewnwnwswnwenww
wwwwwswwwwwwwswwnwwswswswe
seswneswsenwweenwswnwseeneneswseseese
nwswsenwwseswseswswsenwewenwnenwnwew
swnenwnenwneneneneneneswnenenwnenenesene
weenenenwneeneneeneseese
nwnwnenwswnwseesewneenenenewnwne
eenweswenwseeneeeeseeeeeeew
seswsewseseseswseseseswsenwseseswnesesese
seseswseseseswnesesesewseseseswswswsese
wswswwswneseswwswnwswswwswswwwwsw
swswswseeswwswswswseswseneswswswseswsw
nwnwnwnwnwnwnwswenwnwnenwnwenew
nwnwnwnwnwenwnwnwnwwwnwnwwnwnwnwnw
nwesweenweeeeseesweeeeeeene
nwwwnwnwwnenwnwnwsw
nwnwswwnwnwnwnenwwsenwnweswnwnwenwnw
seseseesweseeenwseneeeee
nweeswswesenenweneswnwenwneweneesw
eeseswswseswwneswwneseseswwsenwseswe
neeneeneneeeweeseneneneneseneneew
nwsewnwnwnwwnwnwwnwsewwnwnwnwnwnwwnw
wswswneswwnwswwswweswwwswwsww
sesenwswseswseswseseeswseswnwsesesesese
nwenwnenwnwwnwnwnenwwenwnwnwnenwnene
sewseewswnwenwswneenenwnwnenewsww
nenwnwnwnwnwnwnwnwneswnwswsenwnenwnenwnwnw
seseseseseswseswwseseseeswseswswewsw
neseneenwwwsenesesenenwwe
wwswswneneswnwsewswswswsewswswseww
sewewswwwnwnwsenwnwsewnwwnwsewwnw
wnwnwwwwwnwewnwwnwnenwsww
wwswswswewwnewswnwwwwnesw
swwwwewnewnewswnwwnwnwsewnesenw
swnwnwnwnenenweswenwnwnwnwnwnwnwswsenwsw
eneneneswneeeneenene
swswnwswswswsweswswswswswswswswswswnwswnee
wwswwwswnweswwwnwwwweweew
wnwnenenenenenenwnenwnenwnesenenenenwnesenw
nenweenwnwsewenwneseswsenwnwnwsesesese
wwneeseswseesenenesweneswneswnenwnenw
swswswwswwwwswswnwswwwnewwwwswse
seeseswswsenwwswswsesenwswswesenwese

View file

@ -3,18 +3,35 @@
module Day17 where module Day17 where
import AoC import AoC
import Conway
import Data.List import Data.List
import Data.Vector.Sized (Vector) import Data.Vector.Sized (Vector)
import qualified Data.Vector.Sized as V import qualified Data.Vector.Sized as V
import Data.Map (Map)
import qualified Data.Map as M
import Data.Set (Set) import Data.Set (Set)
import qualified Data.Set as S import qualified Data.Set as S
class Index i where
neighbours :: i -> [i]
addIndex :: i -> i -> i
instance (Num a, Eq a) => Index (Vector n a) where instance (Num a, Eq a) => Index (Vector n a) where
neighbours i = filter (/= i) . V.mapM (flip map [-1, 0, 1] . (+)) $ i neighbours i = filter (/= i) . V.mapM (flip map [-1, 0, 1] . (+)) $ i
addIndex = V.zipWith (+) addIndex = V.zipWith (+)
counts :: Ord a => [a] -> Map a Int
counts = M.fromList . map (\xs -> (head xs, length xs)) . group . sort
neighbourCounts :: (Index i, Ord i) => Set i -> Map i Int
neighbourCounts = counts . concatMap neighbours . S.elems
update :: (Index i, Ord i) => (Int -> Bool) -> (Int -> Bool) -> Set i -> Set i
update create destroy old = M.keysSet $ M.filterWithKey shouldLive $ M.fromSet (flip (M.findWithDefault 0) nCounts) indices
where nCounts = neighbourCounts old
indices = S.union old $ M.keysSet nCounts
shouldLive ix n = if S.notMember ix old then create n else not $ destroy n
run6 :: (Index i, Ord i) => Set i -> Int run6 :: (Index i, Ord i) => Set i -> Int
run6 = S.size . (!! 6) . iterate (update (==3) (`notElem` [2, 3])) run6 = S.size . (!! 6) . iterate (update (==3) (`notElem` [2, 3]))

View file

@ -1,33 +0,0 @@
module Day24 where
import AoC
import Conway
import Data.List
import qualified Data.Set as S
import Optics.Core hiding (Index)
import Optics.TH
data Coord = Coord { east :: Int
, northeast :: Int
} deriving (Eq, Ord)
instance Index Coord where
neighbours c = map (addIndex c . uncurry Coord) offsets
where offsets = [(0, -1), (0, 1), (1, -1), (1, 0), (-1, 0), (-1, 1)]
addIndex (Coord x1 y1) (Coord x2 y2) = Coord (x1 + x2) (y1 + y2)
parseSteps :: String -> Coord
parseSteps [] = Coord 0 0
parseSteps xs = case xs of
('n':'w':xs) -> go (-1, 1) xs
('w':xs) -> go (-1, 0) xs
('s':'w':xs) -> go (0, -1) xs
('n':'e':xs) -> go (0, 1) xs
('e':xs) -> go (1, 0) xs
('s':'e':xs) -> go (1, -1) xs
where go (e, ne) xs = addIndex (Coord e ne) $ parseSteps xs
main = runAoC (onlySet . map parseSteps . lines) length (length . conwayN 100 . S.fromList)
where onlySet = map head . filter (odd . length) . group . sort
conwayN n = last . take n . tail . iterate (update (==2) (`notElem` [1, 2]))