From 3ebbba39535953d13af8a545a8e3eea415e0f337 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 24 Dec 2020 15:10:48 +0100 Subject: [PATCH] 2020: day24: part 1 --- .../aoc2020_bench/benches/aoc2020_bench.rs | 2 + aoc2020/input/day24.txt | 608 ++++++++++++++++++ aoc2020/input/day24_provided.txt | 20 + aoc2020/src/day24.rs | 144 +++++ aoc2020/src/lib.rs | 1 + aoc2020/src/main.rs | 2 + 6 files changed, 777 insertions(+) create mode 100644 aoc2020/input/day24.txt create mode 100644 aoc2020/input/day24_provided.txt create mode 100644 aoc2020/src/day24.rs diff --git a/aoc2020/aoc2020_bench/benches/aoc2020_bench.rs b/aoc2020/aoc2020_bench/benches/aoc2020_bench.rs index a786c61..5644cd8 100644 --- a/aoc2020/aoc2020_bench/benches/aoc2020_bench.rs +++ b/aoc2020/aoc2020_bench/benches/aoc2020_bench.rs @@ -22,6 +22,7 @@ use aoc2020::day19; use aoc2020::day21; use aoc2020::day22; use aoc2020::day23; +use aoc2020::day24; fn aoc2020_all(c: &mut Criterion) { c.bench_function("day01", |b| b.iter(|| day01::run().unwrap())); @@ -46,6 +47,7 @@ fn aoc2020_all(c: &mut Criterion) { c.bench_function("day21", |b| b.iter(|| day21::run().unwrap())); c.bench_function("day22", |b| b.iter(|| day22::run().unwrap())); c.bench_function("day23", |b| b.iter(|| day23::run().unwrap())); + c.bench_function("day24", |b| b.iter(|| day24::run().unwrap())); } criterion_group! { diff --git a/aoc2020/input/day24.txt b/aoc2020/input/day24.txt new file mode 100644 index 0000000..ca022f3 --- /dev/null +++ b/aoc2020/input/day24.txt @@ -0,0 +1,608 @@ +wwwnwsenwnwnwnwnwnewnewsewnwnwnww +nenwnwnewnweewsenwenwnwwswwnwswsw +seswswseneeeswswnwnwswseswnwswswswswsw +swenenwneswswswswsenwswswnwenenwseswsw +wneneenwseeeewneeseneeeneeenenene +wwwwenwwwwwnwnewwnwswwwwwse +neneneneneneeneswneeneenwneeneneenesw +seneseswseseswswseseswswseswsewsesesesw +enweneeeeeseeeesw +wwwsewswwwwswwenwneew +sesweenwseeneeeswneeseeeseswenwsese +seswswwswswswswseswswnwswswene +swwnwwwwwwswnwwwseswwwwwseww +wwnewwsewwwwswwneseweewwnw +wswswseneswswseswseneswseswseswswseswnesw +nenwnwneneseneeneswnewenweeswneeese +wwenwwwwnwwwnewsewwnwwwswwnw +newnwswneswswswneeeneenenee +swwsewswswswnwswswswnewewseswswswsw +eseneeenwseesweesw +wnenenenwnenenwnenwnwnenwnwsesenwnesene +eswneeeeeeeeneeeneenenewnee +enwenweeweewesesesweswswnweew +eseeseseseeswsewswww +wseeneewnwswswenweee +swwneswswwwwwswwswwwswwseswww +wesesesewsweseenwnesewneneswseswsw +nwswsesenwswnenenwenenwne +neeneseenenweneneneeeweeneeeswe +wwnwnwwwwsenwnwwnwwwnwwnwnwnw +eswnewswwnwnwwnwnwnwenwwsenewenww +wswsenwsewswseeneseseswswswneseswsw +sewswewwwnwwwnwwneewnwnwnwswnw +wsweswswwnwwsweswswswswnwswswswswswswe +swneseswswswswswsesenwsesw +neeeesewseenweeesweseeeeeee +nenenenenwnenenwneneneneeswswnwnenenwnwnw +nwwwewnwwnwwwwnwwnewnwwwwsenw +senwseeeesenwseeeseenwsweseseswnee +seseseeesenwseseeseeseseesesese +nwsesesesenwseseeseseseswewseswswswsw +wwwwnwwwwwnwnenwnwnwewnwwswww +neneneneswneswneneeeenwneneneeenene +seswnwseswsenenwnewseneswsenwsenwseenwswse +neeswwewwwnwneswnwwswswnw +eswwwswwnwwswneswwwsweswwweww +nwswwsewneeeneswneeeeeneeneneesw +eeswewwneseneneeneeeneseeeneneee +seseewseeseneweeeweesewsenewe +swseswwswneswswswsewsweswnwswseswwe +nwnwenwnewnwsenwsewwnwwnwnwwwnewnw +nenwsesesenwwnwsewenwwwwweswwwwe +nesenweseeeseeswsewsewswwseeeese +sewwswseseseneseswnwesenwseesenwenw +weseseseesesesesesenwseseseseesesese +swwnwnwnewnwnwwnwwwew +nwnwnwnwnenwswnwnwnwnwnwwnwnwenwsesesew +swsewwneswwnwswseswwneswswsewnewnew +wwwwnwwswwnwnwewwwwwwnwwnw +seseseseseeseseeseewnweseswnwesesese +nwwnenwnwwnenenwnwnwnwneneenenenwnenwse +nwwsenwnwnewnwwwnwwnwnwnwwnwnwwsenww +sesewsesenweseseseseseseswsesese +seewneswwwwnwwwseswwnwewnwnwnw +neneneneneneswneneneswswe +wwwwwwwwsenwwwwwwwwww +wnwwwnwwnwsewnwwwwwwswe +nwswnwnwewnwsenwneneneneswnwenene +senweweneseeweeeseneeeweeenw +wnwnwwwwenwwwswnwnwewswnwnewwne +eewnewswnenwswwswwsweeseswnwwnw +wsenenenwnenenwnwnenenenwnenenenenenenw +swseswwswwswnwswswseneseeesw +eeenwnweeeseeeeeeeeeswee +seseneewsesesenwseseeseswsesesesese +swswwswsweswswwswswsw +seseseseseweeeeeeseeseswneeenw +nenwnenwneseneswnenwnenwsene +neneneneneneneswenenenenene +nwnwnwswnwnwenwneneneneeswnwnwnwwnwne +wswnwneneenenwneswnwneswnenenwswsenwnwe +nwnwnwswnwnwnwsenwnwnewnwsenwnwnwenwswnw +seneneneneenenweenenenenenenenenenew +nwwswnwnwnwwnwnwnwnwnwwsenwnwsenwenw +seseseseswsenesesesesesesesesese +enwwwwenwswwswnewwswwsesww +wnwsenwnewenewswswswseewwwwswswswe +seswswnwswwwswswenwneesenwswswswnwesw +sesenwnwswsesesesesenewsesesenwsesesee +wseswnwswseseseeneeswsesesesesewsesene +swwseneswnwwwswnwwewwnewweewsww +neswseenwseneneenesenenenewnenewswnee +eeseeseweeeseeeeseesesesee +esesewseseseseneseswsenweseeeesese +wwnwnwwwwwwwnwnwnwsenewnwse +seenweseseseseeeseswnweeseseeenee +swswwswwwwwwwwwwnewwwwnenew +nenenenenenenwnesenenenewnenenenenenwne +enesweeeeenweeneeenwsww +eeneeeeeeneeeseeeeeeewswe +sweeeeeeeeeeeneeneee +wnwnwwwsenenwwwnwnwwnwnesesenwnewsw +neneeenweeseneeswneeweesenwneee +seneeeseseswnesewswnwneswswnwsewwnwnwsw +nwneeenwnenenenwnwnenenenwnwnewnewne +neswnwsweesewswswnwwneswswwswneswwsene +seeseseeeenwswseeenesesesenwsesewse +nwnwnwnwnenwnwnenwnwnwenwnenwenewwse +enwnwnwnwnwnwnwnwnwswnwnwswnwswnwenwnwnwne +nwwwneneswswneeewnwwnwswswseeseseee +nenwnwswnwnwsewneneenwnwwnw +senwweweswnwneeneseeeswnweseswse +wnwwnwnenwnenwsesenwnwwnwnwswnwswnwnwnenw +wwnwnwsewnwnwwnwesweswnewwwswne +nenenewneswneneswneeweswneenwnesenw +eswnwwwsweseswwswswwwnwswswnwswsenw +eeeswsenwseeweeeeeeseeeeee +nwwwnwsewwnwwnwwwwnewwsewwnwwne +seseseesesesesesesenwseseseseseseseswsw +nwnwnwswsenwnenenenenwnwnwnwnwnwwnwne +nwsesewesenwnwnwnwswsewenwswnwnenwwe +newneseneneseswnwnwswnwewswnwnwseesw +eeeeeeneweeeneeneswneeseene +nwnwwnwnwnwnwwwswnwnwnwnwwewnwwswe +swswswseswneseseseswswseseswswswnwsesesesw +eeseneneseweneneeeneeneenwneewne +eseeswseeeeseeneseeeenwseeeese +sesesenwsesesesewsesenesesesesesesesesesese +senwseseseseseseseseseseseseseseswsesenwsw +neeneneswnenenenenenenenweneneneneswne +swswswseswwswswswswnwswswswswwseswswnwsw +neeeeeeseneeneswwneeeeeneeee +enweesweneneswweneeewenewenee +sewwswswwseneswwwsenwwswwwnewwww +wewwwenwseswnwwwwwwewnwnwnw +nwwenwsewswwwsw +neneneeneneneseneneweseenenweenenene +nwswswneswswwnwesenwsweswswswsw +swenwnwnwnwnwnwnenwsenwnwwnenwnenw +swseseneseseseseneswwsewneseewswnwsene +wneeneneswnwneneewneneneeneenenee +eenwneeweeeeeeesweeeee +seneeswnenweweweeweneeswseee +swseseesewswswsenwswswswswswswsw +wswwswwwswwswwwwnewwwwsewnesw +nwnenwsewnenenenwnenwnwnwne +neenwneneneneneseneneneenewnenenwnenesw +enwnwwnwnwesenwswnenwnwnwenwnwnwswnw +swnenwswsweseeswswswseseswwnwswswseseswsw +nwswnesweswswsewswseswnwswswswswneseswesw +swneseneswswwsenwswswswsw +eeeeseeeeeeeweeeeeneee +wnwwnwswewwnwwwwwwwseww +neenenwswnenweneeeeseneseee +neneweneeeneneneswnenweweeseene +neeswnesenenwnwnenenwswnenenwswwnesenw +senenwnenenenenenwnene +sewnwneseeweswseeseenesesenweswwwne +swswnewseswswswswswwseseswswseneswswswsesw +nwnwswenwnwnwnwnwnwnwnwnwnwsewnwnwnwnenw +eseneswswnwswnweneeeeeeeeeeee +nenwnenwnwnenwnenwnwnwneswnwnenwe +senenenwsweswsweseenwnwwswnwswswswnwwe +nweneeneseneswwneswneneenewneeneene +seeseswnesenwnwenwnwnweneswwwnenwnwwnw +eseseeseeeseesesenesenweeseswsesese +swswsesenwswswswsenwswneswswseneneswsew +nenwnwnwseewnwwnwnwsewnew +swswseswswswneweswswswwswswswswswswswswse +wswsweswswswwsweswswwnwswswswswww +swnewwsenwwswwnewnwwsewwswnwnwne +wnwwwwnwwwsewnenwneenwswsewwnwww +nenweeeeeneeeesweee +sesesenwswswneswenwswwswwneswnesw +swswsewswwswswswenewswsww +seswseesesesesenesese +nweeseseneswwewseswseneseeeeeese +swnwswswseswwsweswwwswwwwewwnw +wnwnwnwnwneswnwnwnwnwwnwnwnenwnwsenwnwnwnw +nesenenwwneneswnenwnwsewneenwnwnwnwnw +eweeneneeseneeenweneeeneseenene +nwwnwnenwsewnesewwewwnewwnwese +eseeseseeeeseseenweseeseseeesw +wwnwwnwwewnwnwnwnwwnwwwnwsww +wnenweewsesewww +nwseseseseseseweeseeseseseseseesese +seseswwseswswsesweswseseswswswsesw +wswswsweswswwswswswwswswwsw +eeeneenweneeeeeeeewseseene +neneneenwseseswswenewsenenenwwsw +nwnwsenwnwsenwnwwnwnwnwnwnwnwnwnwnwnwnw +eeneseseneenenwewneeeeeneene +wwswswswwwwswswswwswwnwsewsw +senewseseewnwswseseseswseseswseswsesese +seswseswnwnwweseneseswsesesweseswsew +nenwnwseswseeweewnwnwneswnwswwnwsww +nwnwnenwnwnwnenenenenwnwnenesenwsenenenwnw +sewnwneswsewwswnwwseewnenenweswne +nwseswnwswsesenwnwnwwswnenewseswsewe +newnweseswsesenwwnwwnwnwnwnwnee +swwnweswwneeswnwswenwnwswswwswwse +sewwnwswenwwwwsewnwwseswneeswneswe +wwwwwwwnwwnesewwwwwnwnwww +seenwwswenwswnweeeeeeseeewsese +wswnwwwwwsewnewwswsewswwseenw +nenenenwwenwnwnenenenwnwnenesenwnwwse +nwnwnwnwnwnwwnwenwnwnwnwnwnwsenwnwnwnwnw +seseswseswnwseseseseseseseseswnwsesesesw +wnwwwwsenenwsenwwnenwwnwwwwenwnw +nwnewseseswsewnwnenwswnwseenesewnwnenw +neswsewwwwweneswwwweswwwnenw +nweswneneeneeeeneneneneswneneeneee +wswneneseeswswsewsenweseseswenwnwsw +sewswnwnwnwnenwnwnwnwswsewwwnwnenwwne +swswwswswswwswnenwswswsweswsenwweseswse +neseswwwnwnwnewnwseswnwwwenwnwnwe +swwswswswseswneswswwswswswwswnwswsesw +wnwnenwneswwnwwnwnwwsenwwnwwwwnw +wwnewsenwwnwwnwwwnwnwenwwnwww +swseswnweewwswnewswwenesenewswnw +eneeseenwsesweeneenweenwwesese +sesesewswwswswswswseeseseseseseswewe +nenwenwnwwnwnesenenwnwnenwswnwnenenwe +seenweeeseseseesenwseswseswsew +nenwnenesenwwnwnenenwnwnenwnwnenenenwnw +nwswseewswnwneswswneseseswsewseswnwse +nweneswwnwnwwwewsenwwwwwnesww +neeswswswwwwnwsewneswswswsewwwwww +wswseswneswesewneneesesenwseenwenw +wewwswewwnwwsewwwwwnwnwwwne +ewseneesesesesenwseesesweseseseee +nwenesweeeeeneneeneneneeneeee +nwswseswsesesewswseseswseseneseswse +wnwnewneneneswewneneneeneneenenenene +nwnwnwnwnwnwnwnwnwnwnwnwwnwenw +wwswswwnwwwwswswwweswwwwsww +seseseseewseseswnwneeeseseesenesese +neenwnwnesenwswnenweenwsewnwwswwnwse +swswseswnwswseswswswseseswseswnwsesweswswsw +eseeeseenenwenesweneweeenwwse +nwwwwwwwnewwwnwsewwwewwwsw +swswseswseeswswseswswswswsenenwwseswsw +nwneswseneneseeseseeswseswsenwseseswsese +nenwwwwwwwwseseweswwwwwww +wsesenwwseeseneseneneswwseseeseswsese +swswswneswswswwwwwwswswswswnwsewswse +eesewsesewneswseneeseenweeswese +swsenwsenwswneswswswseswseneseseswsesenwse +wwwswnwsweswwesewwwwwwswwwe +eswswnwwwwnwweenwwwwwwnwwnww +seweeeneeneeeeenwsweneneewswsee +nwswnwnwnwwnwnwnwsenwnwnenwnwnwnwwnwnw +sweswwseseswsesesw +nwwnwenwswwnwnewwswsewnwwwewwwne +nwnwnwnwwwnwnwnewnwnwnwnwnwwsenwnww +wswswswneswseswswnwweewswwswswwswsw +neneneeneswnenwnenenesenewneeneeene +neswseseseneseeewewneseseseseseswnw +sesweswnenenwneneeneneneneenenwnwsenene +nwwenenenwseewwseseswnwwwwwenewe +nwnenwnwnenenenenesewswnenwneenw +neeneneneneenewseneneneenene +wwwswwesenwswneswswswwwswneswswswsw +sewwwwwwwwwwwne +seseeeeeseseseseweneseseswsesewsenw +seeseeeseewseeneseseeesesesesee +wswwswwwwswweswsw +nwswnwnenwnwneswnenwnwnwnenwnwnwnenwnwne +wswnenwnwnenwnenwswnenwsenenenenenwnwenwne +enweeeeeeeeseeeswewweeee +seeeesweseeeeseweseneenesenwsese +nenwnwswnwnwwswwsewnwnwnwnewnwwwnw +sesesweneweseswseseseswnwsesesesesesese +senewwwswswwnewwnewsewnwwenwsenww +wwwsenwnwwnwnwnwnwwnwwnwwnwsewnw +swswswswswseswswswswnewnwwnwswwwswe +seeeneeseesenweseeeewseeseswnwsw +wwswnewewsewnwweswwwwswswww +nwnwwnwnenwnwswnwenwnwnwnwnenwnwnwnwnwnw +neneeneneeneeenweewneneswne +nesenewenenenenwnwnenenesenewsenesewe +seneeseeswesesesesenweeewese +sesesesesesesesenwesesesesw +wnwwnwwsewwwsenenw +neneeneeeneneeeeenwesweeeee +eeeseneneneeneeneneeneewewee +seseseseseseswsesenwsesesesesesese +wsweswswnewswwsweswwswwswswwnwswne +wswseswwwnwswswesewswneswnwwwnee +eseseseswneseseeseseseswseneswnwsewsesww +nwnwsenwnenwnwnenenwswwnwswwnwneeee +neneeeneneewwneeneneneeswseneneeee +nenwewnwwwnwnwsenwse +nwnwnwnwnwnwnwnwswwnesenwnenw +nwweseseseseseeeseseseeeenesesese +nenwnenwnwnewswnenenenwnesenenenenenesenw +seneseseseseseseeseseseseswew +neseeneenenenenenenenenewneenenwene +nwnwnwnenenenwnwnenesenenenenwnenewnwne +swseswswseswnewswwswswseneswneswenwsw +eeneeseenwesweeneweeseenwene +wswseseseseneseseseseswwseneswesesenenw +sesesesesesewseseseseseseseeseneswsesew +nweswnwnwesesweseswswnwnweseenwsene +seneseeseeeeseweseeeseseesesese +wneeneeneweneseneneneesenenenenene +seseesesesewwseseseseeesesenwsesese +neneweeseneewnwseneneeswneneeeneene +neswenwswseseswswneswnwenenwseswsenwnw +swswnwseseseseswswsweswnwsenwswnwsesesese +wnesenwwwweswwwwwwwswwwww +eswnwwswweweeeswnweswnenweseww +wwnwwweseswnwwnweseeneswswe +wnwnewwnewwwwwwnwsewwwwwsww +neswnenenwneneneneneesenewneneeeenene +wneewnewsenwsenwnewswesenwswwnewsw +nwsesesewwnenwnwe +nwnenwnwnwwnewenwsenenwneesenwnwnewse +seneseswseseseswseswsewnese +swseswswswseeswswswswnwsesesesw +newnwseeenwnwwswnenenwnwnenwnw +swwwnwswswswsewwswewwswwswwwnesw +nwnenwnwnwseseneenwnwnenenwnwnwnwsewsw +seeseseseseseseeswnwsesesesesesesenw +sewenewnwneneewnwnwnwnwnenenwnwnenwnw +neneneesenenwnwwneneneneneneenenwneswnw +wwwwswswswswewwenwnwwswwwswsew +senwwwwwwwnwwwwwwwwwweww +sesesesesesesesesenwsesesese +nwwnwnwnwnwnwnwnwwnwnwwnwsenwnwnww +nenwnwnwnwsenwnwnesewnenwnenenwnwnwnwnenw +nwneneeeeeeeeeeneeeeseswee +swseswseswswswswswswswseswnwsweswswswsw +swswswnwswswswswswseswswswswneswswswswse +seseewsesewwnwnesenenenenenenewnenesew +neswseswnwseswswswesesweneswnwseswnwsew +senesewnwswwseseseseseeeneeseeese +nwsweenwenwnwnwwnwnwwnwnwnwnwwnwswsw +seseswswswnenwseswneeswswswsweseseswnw +seseswseswswseseneseewseswswseswswsewse +swswswwsesewswswswswwswnwwwwneswswnesw +eeeeeeenweseeesw +eeeneeeneeweseeeee +nwnenewneneneenwsw +neeneswenwweeswewwseenenw +nwswnwewwnwnwnwwsenwnwnwnwwnwnwnwsenww +enewenwseneneswnwnesewsewnenenwneseswne +seneswswseseswswesenwsesw +nwnwnwwwnwnwwnwnewnwsenwwnwnwnwewnw +nwnwnwswswwnwsenwnenwenwnwsenwnwnenwnw +nwseneswnenwwnwnenenenwnenwnenene +wswswswswwwwswwswsenwwswswswsw +wwwnwnwwenwwsenwwwwewwwnwww +eseeneswseenwwseeeeswsesenwswwe +neseeswnenwwnewsesesewsweneseeswsese +seswswwseswswswsenwseseseseseeseswseswnw +swnwswwnweweewwwswwwwswesww +nenwsenwenwnwnwnwnwnwnwnwwnwnwnwnwnwnw +swswseswneswswswsenwseswswswnwneseewswsw +neneweenenenesenenene +swneswswswswswswswswswsw +nenenenenenenwnenenesewnenwnwnenenesenene +eneeseeeeeeeeeeseeewesee +seeseeseseeneseseeeseseseswese +seseswenwswnwseswswswswseseeswswseseseswse +nwwnwwnwnwwnwnwnwseewnwnwnwnwnw +seneswswswwswswseneswswseswswswseseswsese +nenenwneneneenwnwwnenwnwseneswnenenwnw +seseewsenwneeneswenwnwneswenenenese +nwnwsenenenwnwnwnwswnwnenwnwnenenwnenwne +nwnwnwwenwswnwnwnwnenwnwnwwnwwnwwwsww +swswnwseseseneswneneesewseenwnwsesew +neneenwnewneswnenwnenenenwne +wswswneseseswseswsesewswswseseseseseese +nwnwnwnenwnwnwwnwsewswnww +wwewnwwwnwwwwnwwwnwnwnwwwsw +swsesewsewnenesenesesesesesenweswsese +newnenwswnwneneweswsenenwenenwnenwese +swswswswswwswwswswswsewswswnwswswswwe +ewswneswnwwswwwwwsewwwwwswwww +wwwwwwswwnwnwwwwweewwwww +wswseneswnwneswnwnenenenwwsenwnenwnese +nwnwswneswnwnenwwnenwnwenwnwnwnwwnwese +neenenenenewneneneneneenene +weewneswseneneseneswnenww +sesesesesesweseseeeseesewseewwenw +nwnwnwnwnenwnwnwwwnwsenwnwwnweswnwnw +nwnwnenwwwsenwnwnwnwnwnwnenwnenwnwnwnesene +swseseseseswseseseseseswsesenwnwsesesesese +wwwnwwnwnwnwewwnwwwewswnwww +seswseenwseseeeweee +swswswnenwseswnwseeseswneseseseneesesww +neeneenwswesweneneswswneeneeswene +nwswswweesewwwnenwwewwwneww +neeeeeewseseseeeseseee +sesenesesesweseseeswseswseswwseswnewnww +newenwsewseweseseseseseswseseenesesee +seseeseewenwwseeseseseewneesesewse +nenenenesenwneeneswneneneswneeeneneee +sesesesewseseswseseseseneswseseseswsese +newnwnenenwnweneneeswnenwnwsenwnwnenene +swswswseswswseswswswneseswnwswseseswesw +nwneswswnwnwenwnwnwnwnwnwne +wnewswwsewwenwwwwnwwnwwwnew +swsenweseseeeenwseseeeseseneesewse +wwenwwnwnwwnwseewnwwewsewnw +nenenwnwneseswnenwnenwnenwnenenwnenenwnene +seneswswswswnwswswswswswswseswswswswswse +nwweswwwswseswwwwnewwwwwswwswsw +wwneswnwnwnwenwwsewwnwnenwnwwnwsenesw +sesewnwnwnwswsenewwnenwnwnenwnwnwnwnwnenw +swnwswswswwswswswswneswneseswswswswswsw +wswwneswswnewswswsesesesesesenweswsw +neseseswseseneswwswsesewseseseseswswsese +swewneeswswswswsenw +esenwnenwswsewswswseswseswnwseswswswswse +swewswneeeseseseeeeeweeenenwe +nwwnenenwwneseneseneneewseneneneeswne +nenewnenwenwneweswnwne +eeeeeeeeeseseewweseesenesene +swnwswnwenwewwwswnwswnwwnenenesesw +seenesweswsesweeeenewneneenewesw +seeseeweseseseseseseseseseseseewsese +swswswneseneswswswwweswseswseswswswsw +sweeeeeeeeeneeneneeswene +eswwsenwswswswseswswswswswswwswnwneswsw +sesesesweseeseneeseseseseseseseseswene +enweseseeeseeseseseneeesweeese +wwswwwwwswwewwnenewwwswwww +seewnewenwneseeeweeesweeeseene +seneseneneneenenewneenenenenewnenene +wnweseswswnwnweswnwenwswseeswswswswnw +nwneneneeneneswneneneneneneneneneneswnenene +nwnwnenwnwnwsenwnwswnenwnwnwnwenwnwnese +nenenwneneneneneeneeneeneneneeneswne +nenwneeseenenewsesweneenenenwneeene +neneneeneeseewneeneewwe +wenwsesweseeeenwesewenweesesese +nwnwwnenwnwnwsenwsenwenenwnenwnwnwnwnwnw +swesesewseswswseswswswseneneseseswnwsesw +nwnenwnwnwnwswnwnwnwsenwnenwnwswnwwnwne +eswwswseswsewenwnewwnewseswneswwnwsw +swseswsesesenwseseseseswsese +esweswnwewsenwsewse +wsesewwwwwewnenewnwwswwwneww +swseseswwswswseseswswneseswswsesewswneswsw +swswswswseswseswswswswnwnwswswswseswnesw +nenenesenenenenenenenenenenenenwneneneswne +eseswesewnwseeseneesweewseseenwese +swwswswswnwseswswswswwswsweswswswswswsw +neseeenwnweswenwsewseseneswwswnwsww +swswwswneneswswswswnewswseswswsenw +senwnenenweneneeneswneeneneeseeswnew +nenwnwnenwnwnenwswsenwnenenenenwnwwnwe +nwwnwnwwnwnwwnwnwnwnwnwnwenwwnwnw +swswswseswswswswswnwwseswenwswseswsweswe +wnwwwenwsewswwwwswnewwwnwwww +nwwwnwnewsewwwwnwnwwwnwnw +nwswweswewswswnesw +sewsweseswswswswnwsweswswswswswswswse +ewneneseeseneeeeeneeneenwnwnee +seswswswwseswswseswswswswswneswsese +eeeneeseeeeeseseswesese +neswsenwwenwnwsenwswnenenenenw +eswewswwneenenenenwsenwsewnwenewnw +wwswwswwenwswwewswswwwwwwsw +eenenenwwnesweeenenewseswenesene +seswneneneseswwenwnweneneneenenenene +wenwwnwswwwnwwwnwnenwnwwnwswwe +nenenenenesenwneweneenenenenenenesene +wwwwwwwwswwswwwnwwswswesww +wwsesenwnwnwnwwnwnwnwnwnwnwnwnwsewnw +senewnwenenenenenewneneneneneneneswneene +sesewnwneneneneneneneneewneeneswnw +swwswswswswswswnesw +swweneswnwwnwwneswseswswesewwswse +neneesenewnewneneenenewnenenenenene +nwnwswneswseswnweee +wenewwwseseswnewwwwnwwswswswwnw +swsewnenwenwsenenwse +nenenenenwneneneenenwnesenenenenenesenene +newwwwnwsewwwwwswswwnesewsww +wnwenwwnwwswnwwnwwwwswnwnwenwnw +weswswwwewsweswswwswwwwswww +seneeeseenwsesenwswsweesenwseeeewe +swnwenenenenenenwsenenwnwnenesenenenwnwne +nwnwnweswenwnwnwnwnwnwwnwswwne +swswwswswswseswswswswsweswnwswswswesw +nwnenwnwnwnwneswnwnenenenenenewsenenwnenw +nwsesenenenenenenenenenenenenenenenenwsenew +eseeeeeeeeeeeeweene +senwnwnwwenweswnenwnwneewnwnwwww +swnwsenwswneneneenweswseweneneneee +weeeewseseeeeseeeseseseseee +wnwenwnwenwwneswnwwnwneneeswnwenw +nwsenwnwnwwwnewwnwseneseswnwnwwnenwnw +nwnenenwsenwnenenenwnenenenewnwnwneew +senwnenwnenwnwnwnwnenwnenenwwsenenwnwnw +enwwwnwnenenewneneswenenesewenene +nenweneneseeenenwenwnenewneswseneswe +wneseneneneenwneneneneneswnenenenenenenene +neneneeseeneeneweneeneneenene +eenesweeneneneneneneneneeenene +esweseeneeeeneeneneeeeewnwse +sesesweswseseseswseswnwseswseseseswsese +nwnenwnwwsenwnwnwnwnw +nwenenweneneswsesweeneneewneeene +ewneseseeswseeneeeseew +swswwswswnwswswswswwswseswswswnewswewsw +sesenweseeseeeneneeseweswsesesesw +nwsenwseeswswsewwsenenwwnwenenwswwene +swswnwwseeneswwnwnew +swswswseswseswswnwseswswswseeenwswswsese +swnwneswnwwsweswseswwwnwswwswswewse +nwnwnwnenwewnwnwnwnwnwneneswnwnwnw +seseseswsesesweswseswswseneswwseswswsese +swwweswwneswswwswwwseesenwnewse +wswwnwwsewnewswwwneswnewweswswswne +eseenewneneswsesenwneneeneneswswnenewsw +seswesenwnwnwneswswnewwnenwneseneenew +wsweswswswswswswneswswwwswneswswwswwse +swneneneenewneneneenwwsewneeeneswne +nwneswnenwwswnenwsenwnwnwneenwseenenenwsw +seseswseswseseseneswswsweswswswsewsesw +ewneneseeneeneneswnw +eeseswnwseseeeeeseseswnweseeseee +wwewseswwwswswwwnenewswswwwswsw +nwewwenwswnenwseswwnwwwnewnwnwswe +seswseswsesesweswseswsesenwsesesesesese +swswswwwswwswewswswnewwewswwwsw +swnesesenwewwseseeswnewnenwwenese +swnwwseswenwsenwneseseseseseseenwsesw +nesenewsenwnweswwwwnwneswnwwsenenwne +ewnwnwnwnesenwnenwnwwswnwsenenwenwnw +esesewneseseswsenesenwwseswsesesenenw +seneswwwnwenwseswnwwwwwswswwene +eswwnewnenenwnwnwnenwnwnenwsenwneene +wneseseesenwnwseneneneswswwwwnwswenese +nesenwnwwnesenesenenwneswnwneswnwnwnenene +senesesesewseseseseseseseseseseesesese +neweeeeneenenwswenesweeeswneee +swneneenenenewnenenenwwnenwsweenenene +nwwenwwwseswswwneswwsenewenwnwnw +nenenenenwsewneseneswneswnenenwne +swswswwswsweswswswswswswsw +nenenwsenwnwnenwnwnenenenwnenenenwneswnw +neneswnwnwnwnwnenwnenwenwnwnwnesenwnenw +nwnwswswswewswswswswswswswseswswswswsw +weeeeeeenee +swnwswswsenwseneswseeseswswneseseswswnwse +swswwseseswswneswseswswneswseseneswswsw +weesweneseweeenesewesweneesee +seswswswseseseseseseseneseswsesenwesese +eweneseeeseneewnwneeeneneenese +swwnenwswwnwnwnwnwswwswenweenwnww +nwwwwwswwswwwwwswswswwswswwe +eneenwneseseeneneeenwseneswneenew +sesesewneswnwnenewneseeneswnwnenweew +eswswswsenwnwnwnewswnenwseswnenwnenee +enwwwesweeeeeeeeseeseeeeee +eseeeeeeeseeeneseswwseeeeee +nwnenenenenenwnenenenenwneswsenwse +weseseseeseseseseseseseeeenesewse +neeneeeweeesweeswenweeswnwenw +nwwwneswswwswswewewwseswswswww +nenewnenenwnwnwnwnwnenwnwnenenesenwnwnw +esesesenesewseseneseseswsese +sesweswneneneneswwnewnwnenweenenenwsw +nwneneswnwswswwnewneneneseseenwsewnese +wneseewnwnwenwnesenwwseseswwnewnwe +senwwsweeesenwse +wnewwnewsewwnwseswwwswnewwwsw +nwnwwnwnenwnwnwnenwnwwnwsenenwsenwsenw +enwwwwnwwnwnwwwnww +wwnwnwswewneenw +wnewewswwwwnwswwswswseswswwnesw +wneenweweneeweseeeeseeeseee +eeswswweeeneseeeneenwswseseenw +nenenenwnwnwnwnwnwswnwnewnwnenwnwnwenwne +nwswswsenwseswnesewnwswswswswseswneswsw +seeweeeeeseseseseeneseseseseswse +sesewneseswneseeseswseesewwswsesesw +nweneswsesenewweseswwneseneeseswswe +senwseseswsesesesenwesenwsesesewesesesw +eneneneeenwnwnwnwseseweneswse +neswneswnenenewswnesenwnenenenenwnwnesw +neswswseswswseswswseweswswseswswswswsesww +neeeeeweneesw +eneneeeeneswnene +swswswswneswswswswsewswswswnwseswneswswsw +wnwesweneneseseneweeesewswwwnwe +wnwewwwnwnwwnwwenwsewswnwswww +neeswnenwnenwsenwnenewweswsenenwnwswnw +nwswnwnwwnwnwnenwnwenw +swneswswswswwswswswswswswswwswswsw +swnwwnenwneswneenenenenenenwseeeesesw +wnwnwnwnwnwnwnwnenwnwnwnwnwswwswnwnenwnw +seswswnenwseswnwsesweseseseseswseneesww +seewnwnwswneweswwwenewwewsenwse +swswseswswswswnwswweswseswseneseswswsw +neneneeeneeseeswsweeeewneeeenw +swseswseswswswneneseswneswnwne +neeeneeneneneneneswnwenene +swsewewnwnwnenewnewnwwseewseesese +nwnwnwewnenwenwewnwnwnwnwnwswnwnwnwnw +nwwweeeeseswseseseseesenweseewe +sesesewswsweseseswseswswseseswswneenwnw +nenenenenenenwneneneseswneneneswne diff --git a/aoc2020/input/day24_provided.txt b/aoc2020/input/day24_provided.txt new file mode 100644 index 0000000..3dc2f67 --- /dev/null +++ b/aoc2020/input/day24_provided.txt @@ -0,0 +1,20 @@ +sesenwnenenewseeswwswswwnenewsewsw +neeenesenwnwwswnenewnwwsewnenwseswesw +seswneswswsenwwnwse +nwnwneseeswswnenewneswwnewseswneseene +swweswneswnenwsewnwneneseenw +eesenwseswswnenwswnwnwsewwnwsene +sewnenenenesenwsewnenwwwse +wenwwweseeeweswwwnwwe +wsweesenenewnwwnwsenewsenwwsesesenwne +neeswseenwwswnwswswnw +nenwswwsewswnenenewsenwsenwnesesenew +enewnwewneswsewnwswenweswnenwsenwsw +sweneswneswneneenwnewenewwneswswnese +swwesenesewenwneswnwwneseswwne +enesenwswwswneneswsenwnewswseenwsese +wnwnesenesenenwwnenwsewesewsesesew +nenewswnwewswnenesenwnesewesw +eneswnwswnwsenenwnwnwwseeswneewsenese +neswnwewnwnwseenwseesewsenwsweewe +wseweeenwnesenwwwswnew diff --git a/aoc2020/src/day24.rs b/aoc2020/src/day24.rs new file mode 100644 index 0000000..eff4225 --- /dev/null +++ b/aoc2020/src/day24.rs @@ -0,0 +1,144 @@ +use std::collections::HashSet; +use std::fmt::Write; + +use anyhow::{bail, Context, Result}; + +const INPUT: &str = include_str!("../input/day24.txt"); + +pub fn run() -> Result { + let mut res = String::with_capacity(128); + + writeln!(res, "part 1: {}", part1(INPUT)?)?; + + Ok(res) +} + +fn part1(input: &str) -> Result { + let mut black_tiles = HashSet::new(); + + for line in input.lines() { + let mut line = line; + let mut tile_pos = HexCoordinates::default(); + + // compute tile coordinates by going through the whole line + while !line.is_empty() { + match line.chars().next().unwrap() { + 'e' => { + tile_pos = tile_pos.east(); + line = &line[1..]; + } + 'w' => { + tile_pos = tile_pos.west(); + line = &line[1..]; + } + 'n' => { + match line + .chars() + .nth(1) + .context("invalid input, missing char after `n`")? + { + 'e' => tile_pos = tile_pos.north_east(), + 'w' => tile_pos = tile_pos.north_west(), + other => bail!("unexpected character in input: `{}`", other), + } + + line = &line[2..]; + } + 's' => { + match line + .chars() + .nth(1) + .context("invalid input, missing char after `s`")? + { + 'e' => tile_pos = tile_pos.south_east(), + 'w' => tile_pos = tile_pos.south_west(), + other => bail!("unexpected character in input: `{}`", other), + } + + line = &line[2..]; + } + other => bail!("unexpected character in input: `{}`", other), + } + } + + if black_tiles.contains(&tile_pos) { + black_tiles.remove(&tile_pos); + } else { + black_tiles.insert(tile_pos); + } + } + + Ok(black_tiles.len()) +} + +/// Hexagonal tile coordinate representation +/// +/// These use the axial coordinates described here: +/// +/// https://www.redblobgames.com/grids/hexagons/#coordinates-axial +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +struct HexCoordinates { + q: i64, + r: i64, +} + +impl HexCoordinates { + fn east(self) -> Self { + Self { + q: self.q + 1, + r: self.r, + } + } + + fn west(self) -> Self { + Self { + q: self.q - 1, + r: self.r, + } + } + + fn north_west(self) -> Self { + Self { + q: self.q, + r: self.r - 1, + } + } + + fn south_east(self) -> Self { + Self { + q: self.q, + r: self.r + 1, + } + } + + fn north_east(self) -> Self { + self.north_west().east() + } + + fn south_west(self) -> Self { + self.south_east().west() + } +} + +impl Default for HexCoordinates { + fn default() -> Self { + Self { q: 0, r: 0 } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + const PROVIDED: &str = include_str!("../input/day24_provided.txt"); + + #[test] + fn part1_provided() { + assert_eq!(part1(PROVIDED).unwrap(), 10); + } + + #[test] + fn part1_real() { + assert_eq!(part1(INPUT).unwrap(), 528); + } +} diff --git a/aoc2020/src/lib.rs b/aoc2020/src/lib.rs index 47f9f68..017ba88 100644 --- a/aoc2020/src/lib.rs +++ b/aoc2020/src/lib.rs @@ -22,3 +22,4 @@ pub mod day19; pub mod day21; pub mod day22; pub mod day23; +pub mod day24; diff --git a/aoc2020/src/main.rs b/aoc2020/src/main.rs index 896e808..610b152 100644 --- a/aoc2020/src/main.rs +++ b/aoc2020/src/main.rs @@ -24,6 +24,7 @@ use aoc2020::day19; use aoc2020::day21; use aoc2020::day22; use aoc2020::day23; +use aoc2020::day24; fn main() -> Result<()> { let days: &[DayFunc] = &[ @@ -49,6 +50,7 @@ fn main() -> Result<()> { day21::run, day22::run, day23::run, + day24::run, ]; aoc::run(days)