From: Neil Smith Date: Sat, 9 Jan 2021 18:00:01 +0000 (+0000) Subject: Done day 24 X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=d51325ae0b835dd8928bd136d625db22741b4e97;p=advent-of-code-20.git Done day 24 --- diff --git a/advent24/package.yaml b/advent24/package.yaml new file mode 100644 index 0000000..39c7ae7 --- /dev/null +++ b/advent24/package.yaml @@ -0,0 +1,63 @@ +# This YAML file describes your package. Stack will automatically generate a +# Cabal file when you run `stack build`. See the hpack website for help with +# this file: . + +name: advent24 +synopsis: Advent of Code +version: '0.0.1' + +default-extensions: +- AllowAmbiguousTypes +- ApplicativeDo +- BangPatterns +- BlockArguments +- DataKinds +- DeriveFoldable +- DeriveFunctor +- DeriveGeneric +- DeriveTraversable +- EmptyCase +- FlexibleContexts +- FlexibleInstances +- FunctionalDependencies +- GADTs +- GeneralizedNewtypeDeriving +- ImplicitParams +- KindSignatures +- LambdaCase +- MonadComprehensions +- MonoLocalBinds +- MultiParamTypeClasses +- MultiWayIf +- NamedFieldPuns +- NegativeLiterals +- NumDecimals +# - OverloadedLists +- OverloadedStrings +- PartialTypeSignatures +- PatternGuards +- PatternSynonyms +- PolyKinds +- RankNTypes +- RecordWildCards +- ScopedTypeVariables +- TemplateHaskell +- TransformListComp +- TupleSections +- TypeApplications +- TypeFamilies +- TypeInType +- TypeOperators +- ViewPatterns + + +executables: + advent24: + main: advent24.hs + source-dirs: src + dependencies: + - base >= 2 && < 6 + - containers + - linear + - text + - attoparsec diff --git a/advent24/src/advent24.hs b/advent24/src/advent24.hs new file mode 100644 index 0000000..d9bcc92 --- /dev/null +++ b/advent24/src/advent24.hs @@ -0,0 +1,100 @@ +-- import Debug.Trace + +import Data.Text (Text) +-- import qualified Data.Text as T +import qualified Data.Text.IO as TIO + +import Data.Attoparsec.Text hiding (take) +-- import Data.Attoparsec.Combinator +-- import Control.Applicative +-- import Control.Applicative.Combinators + +import qualified Data.Set as S +import Linear (V2(..), (^+^)) +-- import Data.Semigroup +-- import Data.Monoid + + +data Direction = NE | E | SE | SW | W | NW + deriving (Show, Eq, Enum, Bounded) + +type Tile = V2 Int -- x, y +type Grid = S.Set Tile + +instance Semigroup Int where + (<>) = (+) + +instance Monoid Int where + mempty = 0 + +main :: IO () +main = + do text <- TIO.readFile "data/advent24.txt" + let walks = successfulParse text + let grid0 = foldr flipTile S.empty walks + print $ part1 grid0 + print $ part2 grid0 + +part1 grid0 = S.size grid0 +part2 grid0 = S.size $ (iterate update grid0) !! 100 + +delta :: Direction -> Tile +delta NE = V2 1 0 +delta E = V2 0 1 +delta SE = V2 -1 1 +delta SW = V2 -1 0 +delta W = V2 0 -1 +delta NW = V2 1 -1 + + +flipTile :: Tile -> Grid -> Grid +flipTile tile tiles + | tile `S.member` tiles = S.delete tile tiles + | otherwise = S.insert tile tiles + + +neighbourSpaces :: Tile -> Grid +neighbourSpaces here = S.fromList $ map nbrSpace [minBound .. maxBound] -- [NE .. NW] + where nbrSpace d = here ^+^ (delta d) + +countOccupiedNeighbours :: Tile -> Grid -> Int +countOccupiedNeighbours cell grid = + S.size $ S.intersection grid $ neighbourSpaces cell + +tileBecomesWhite :: Grid -> Tile -> Bool +tileBecomesWhite grid cell = black && ((nNbrs == 0) || (nNbrs > 2)) + where black = cell `S.member` grid + nNbrs = countOccupiedNeighbours cell grid + +tileBecomesBlack :: Grid -> Tile -> Bool +tileBecomesBlack grid cell = white && (nNbrs == 2) + where white = cell `S.notMember` grid + nNbrs = countOccupiedNeighbours cell grid + +update :: Grid -> Grid +update grid = (grid `S.union` newBlacks) `S.difference` newWhites + where neighbours = (S.foldr mergeNeighbours S.empty grid) `S.difference` grid + mergeNeighbours cell acc = S.union acc $ neighbourSpaces cell + newWhites = S.filter (tileBecomesWhite grid) grid + newBlacks = S.filter (tileBecomesBlack grid) neighbours + + +-- Parse the input file + +tilesP = tileP `sepBy` endOfLine +tileP = foldMap delta <$> many1 stepP + +stepP = choice [neP, nwP, seP, swP, eP, wP] + +neP = "ne" *> pure NE +nwP = "nw" *> pure NW +seP = "se" *> pure SE +swP = "sw" *> pure SW +eP = "e" *> pure E +wP = "w" *> pure W + +-- successfulParse :: Text -> [Tile] +successfulParse input = + case parseOnly tilesP input of + Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err + Right tiles -> tiles diff --git a/data/advent24.txt b/data/advent24.txt new file mode 100644 index 0000000..408fa7b --- /dev/null +++ b/data/advent24.txt @@ -0,0 +1,592 @@ +wwwnwwswweswwwswwwwswwswwww +swnwwsesenesenenwwnewwwwnwwnwwnw +nenewnesenwnenenenenenene +neeeeewneneneneeeeneeeeeee +swwneswswseseneweseswnwnwseneswswsesenew +eneneneswneeneeeneneeneenenenenene +sesesweseseseenwseseseswsenwseswswswse +eeeeeweneeee +neesewweneewswneeneneseeeeeeee +swsenwswswswswseswseswswswsweswswswswsw +neswewswwsewwwnwsw +seswsenenwswswswseseneseswswswseseswseswse +sewweswneneeneneeeseseeseeneesww +seswsesesesenwnwseseneseseseeseewseee +nwnwnwwewnwwwwnwwwwww +wnwwswwwwwswsewwwweswne +swsesenenwnenwswseseneswseswe +nwwenwwnwwwwwwswwsenwnewnwnwwne +swwwwneswswwseswwswwneswwwswwew +nwneswnenwnenenwenwnwnenenwsenenwnenenw +neneneneneneeneneneneneeneneneenenwnesw +nesewnenwwenwnwwseseeseseneneswwsw +nwnwnwenwwnwnwneswnenenwnenenwnenenwnwne +wnewswwwwswswwswwseswwswswswswsw +nwweswnwswwwswswwnwwsewswswswenesw +neswneneneneneewnene +nwnwswnenwwnwnwnwnwnwnwwswswnewnenwwnw +nenenenewewneneenenewsenewneenesee +nwwnenwnenenenenwnenenwenwnenenenenene +nwsenenenwnwnenenwnesenwnwnwnwnwne +nwneseswwwwswsewwseswswswswswswnewsw +wwwwnwswwwenewnwwwwswwnwww +sesesesesesenwesesesesesesewsweseneseese +eeneneweeeneeseeee +wweswnwwnwnewnwwwswseenwwnwwnwnw +neenenwneneseewnenwnwnwnenenwnesweswsw +seswnwsesewwswwseswneswsweneeseswwe +nenewnwnwnenenenewnwswenwwnesenesenwne +nwenwneswswneeswsesewseww +neneeneneewswneenwneneeneswnenenenee +swseswseseswswseseseseswnwswseswswsw +swneneneswwwneswwsewseswswswswwww +nwneseswnwnwneswnewnwnwnenwnweseenwe +wwwseeenwwnwnwnewnwnwwwnwnwnww +sesesesesesesesewseseseseseseseesese +swswwswseneeswnwwesewswswweneswsw +wseewesenweneenewseneenenwswsee +enewseeseesesesenesesewsewsesesesesee +sewwwswswswwwwswwswswwwswneswsw +nwnwnenwnwwwnwnenwnwnwnwnwswnwwsenwnw +nwnwnwnenwnwnwnwneenenenew +neeneenenenwswwseeneeesenw +eseeeeseseweewseeseeeseeeee +nwsewswseseseseneseswseswseseswe +wwswswwswswnwwenwwwswswwseneew +wwwwewwwwwweewswwwwwww +swswswswswwswnweswwswswsweseswneswswsw +nwewwsenweseeeswneneseneeweewnw +nenewwnwsenwwwwswwsewewwenw +nwwnenwnenwnwnwnenwnenwnwswnwnwnenwnenese +seseneswseswswseswseswseswswseswseseswse +eeeeeeweeeeeeeeeeswenwe +eneswneneswnenenweneneneee +nwswseeneneneeeeeeeeeeenenwenee +swsenewwwwnwwwnewneeswwwnwwswnww +eeeeeeeeeeeeeeweeeee +eseeseseseeeseweneseeseeeeseese +wwwwwwswwnwwwwnwswwnwwneewe +eneseseeseseseneswneenwsewsenewswwswe +senweeeeeeneseneeeseeswnwenwwe +sewsweeneseswneswseswswwseswwswesenw +wwwwwwwwswnwwwwwswwweww +sewnwwwwwsewwwwnwnwenwenwnwswne +eeeeeenweeseeeeee +swsenwsweseswseswswswseswswsesesesesesese +sewswwnwseswswswnweeenwsesesenenesesw +nwnwseseewnenenewewwenwwnwsesenwne +sesesenweseseseneswseseewseeseseneew +swwswsewswsweswswswswseseswneswswswswnw +swseesenwseseweseeseseeseseseeenwe +wwnenwneenwnenenesenenenenwneweseswnwne +nwnwnwnwnwnwnwnwnwsewnwnwnwnwnwsenwnenw +seswsenwsesweswseseseseseswseswswsesene +seswwseseseseseseseseswswsenesesesesese +nwswswswswswneswswswswswsweswseswswswswsw +wwwswwwwwwnesewnwnwsewwwwnwe +seneneneeenewneeeeeenenweneswne +seneenwseseseswsenwwneswswsese +wswwswwwwwswnwsweenwswswwwswesw +eeseseseeeseeesenweeesewswese +nesewswswswnwswswswswwswsweswswswsww +eneswswneeeeenweeeewnwenenwseesw +seneswnwswenwnenenwwnew +seenweweesewewseseeeeeneeew +swnwnwnwnwnwnwenwwnwswenwnwnwnwnwnwnwnw +enwswswswwseseseswsenwseseeseeseswwsw +eeseseseswseseseswsenwwnwseseese +neeeeneswnenenenenenenenenenwnenenee +wnewwwwswewwwwwnwwswseswww +neneneneneneneswneneneneneneneswnenewnee +seeeseeseseseeseseeseswsenwseesesese +swwsewswswwwwswswswsenewseswswnenw +swneseseseswswseswswswseswwseseswswswse +wswweswwnewwnwwww +swswswsesewswswneswswswwsweneswswswsw +wnwwnwwwweswnenw +swseswsweswseswswswswswseswnwswseswswsese +neenesewseneeesewewneneneenenw +seneswseswswnwnwsweswswwswswswseswsenese +nwenwswswwnwwnwnwnwnwsewsenwwwnwnwenw +nenwnenenwnwnwnwnwewnwnwwnwwnwenee +wneseeswwwswsewwwswnww +nwnwnenwnwnenwnwnwneswnwwnwnwnwenwsenw +neeeeneneneneeesweeeenenwswneneee +senweseweseseseeseseseneseseeeswsese +wseseeeneseseneeeeesewseeeweese +seseseseeseseseseeeesewsesesenwsese +wseeseenwseseneeseseeeseseeseeeese +nwwesesesesenwnewwnwnesene +swwneneeeeseeeeeswseenweeeee +nenwseneneneeneeeee +nwwsewwnewwwwwwwww +neneseseenewewwnewnwnwesesenewsesee +neswswswneswnenwwewswneswwswneseswsw +seswswswseseseswseswnewseseswseswsw +wneswseseseenwnewseeswswswnwswsesenw +eneeweneneneeeneesenenenenenenenewse +neswswwwwwwwwwswsew +wneseswnewswwswew +swnwwneswnwewswwswewnwswwwsenwse +wnwnwwwwwnwnwsenwnwnwnwnwnwnwwsew +senwswnwnwnenwswsewneseesenwnwwneenwsw +nesesenenenenwnwneneswneneseenenenwnewnwnw +nenesenwneneneneneneneswneenenenenenenene +eweneesesesesewseeeseeeeeesesee +eeneeweneeneneneneeswnenwneeeswne +wswseswswnwswwswsweeseneswswseseswnw +swenwwnwwsenwnwnewnwwenewwwesw +senwseswswnewswswseswesweswswneswswse +neseneneneeswneneenenenenenenenewnewne +nesewsewwwewwwwwnwwnwnw +swneswwwnwswnewneswwwwwsewwswsesw +nenwwsewnwnwneswsesw +nwnwnwnweseswnenwenwnwnwnwnwswnwnenwnwnw +eswneneeneneneswnenenenenenewseneene +nenwswwwswwwswsweswwwsweswswsww +newneeeeneneneneneene +wnwswewneeewseeseenwswwesenenew +swswswseswswswswswswswswswswwswsweswsw +eeeeenweesweeeeeenweeesw +swswswswswswswswswswneswswswswswsw +eeeeswwwneseeneeeeenweeswee +wwwwwwwwwwwnenwwwwswwww +swwswwnwswwwsewsww +swnweesenwnwsenwswseswwweswswnw +nesenenwnenwnwnenwnwnenenwnenwseenwwnewne +nwsewwnwwnwwwwwwwwwnwnwnwww +eneenewenewneneeeneneeswswneneee +nenwnwnwnwwwnwsenwnwnwnwnwnwnwnwnwnwnwsw +nwnwnwnwnenwnwwnwnwnwnwwnwnwswnwnwnwsenenw +weseeeewneneseseeeeeseswesese +swseseseseeesesesesesesesesenw +nenwnesenwnewnenwnwnenenwnwnwnwnwnwnwnenw +nwnwnwnwswnenwnwnwnenenwnwnwnenwnwne +nwnenweswnenenwneenenewnenenenwnwnwnene +seseeeeseeseseswesenwseseenw +wnwnwnwnwneweswnwwwnwnenwnwwnwnwsew +seneeswwwswneseseswwswseswswswswswswnw +senwwnenwnwnwnenwnwnwnenwnwnwnwnwnwnenw +swnwnwsenwnenwnwnenwnewnwseswnwnenwswne +swswswswneswseswswswsw +seseseswseseseseesesesenwesesesenwnwsese +swswseswseswswswsesesesenesesenwsesesw +wwswwwswwwwswwsewwnewnewwsww +neswswwswseeswwswnenesesesesewswswsw +wwwwwwwswwswseswnewsewswnewwww +swwswswswwswwswwswswswswneswwwswsw +wenwseeeseeseeeseeeseseseneese +neneswnewswwwenwwwnwswsenwwwse +wneweeseeseeeeweenwwewseene +wswnwnweeswesweseenenwswwnenwwnwsenw +sesenesesewseenwsesweeseewesesese +eswseswsenwesenesesesesesewwswsese +nenwwswewwwweseenwsenwwwwnwesw +nwswweswswswswswswneswswwwwnweswse +nwseswseeneseeweesesewneeseeseesene +neeeswewewneseneswneneeneeneenenw +eneneneeeeeweeeneneneeeneee +seswseseswseswswseswseeswsesesewswsese +nwnwnwewwwnwwwwnwwwe +nenenenenwneneneneneswnenenenenenenenenee +wneswneswswswswwswwewswswwwswsesewnw +nenenwnenenesenwnwnenenwnenwwnwnenenenwnw +eneeseswewnwseeswseewweeneswew +ewenweeeeeesesesenweeseeee +nwsenwnwnenwwnwnwnwenwnwnwewnwnwnewne +wsweswswwswwswswwswswswswwswswnwwenw +wwsewwswnwwneeswwwwnwwwswwww +swsewswswswswswswswswswswswswswseseswne +swnwnwnwnwewswswweeenwwnewnwnwnew +seswswswswswneswswseswswswseswseswswswse +nwwwnenwwwnwsewwenwwwswwwwnwww +senwnwnwswneenweneseswnwneeswnwnweswne +wseeeeeeeeenweeeneeeeee +enweeweeenwenwseeneswseneneeeee +nenweeeneseneeeseeeeenesenewwne +nwnenenenwnenwswneswnenenwneneseene +nwnwsenwswnwnwnwnwnwnenwnwwnwnenwnwnwnwnw +ewnwsenwenwswneeseneneswnenewnenenese +wnwswwwwnwsewwnwnewwwwswwneesese +newwnwseswsenenwnwnwnenenw +nwsesesenwsenwseseseeswseswswseswsesese +sesesenwswseseswseseseeseswse +nwneneenwwnenwswnenwswsenwnenwswneneenw +enwswneneneseeeneeneneeewneswneee +wnenenwneneneneneneseswnese +neweeeneeeeeeeeeeeeeee +wswswseswswnwswswswwswswwneswseswswnene +swswseswwswseswsesweswseswseneseswnwswse +wnenweseeesewseseswseseseweswneene +enwswseseswswnwenesesewse +neseneneneneeneenenenenenewswnenenenenene +nwswsweeswseseswseswswnwwswseseswswsene +eeneseeseneeseseesenwseseeswsewsese +sesesenwesenwsweseseweneewseneneese +sesewnwnwwnwnwwwnenwwwewsweww +nwswwwewswwwnwwnwnwwnesewwwnww +enwswnwnwsesewwweneswewwwnwneew +wswswswneseswswwnwswswswswswnenwseswswse +nwnwnwnenwnwnenwnwnwnwnwswnwnwenwnwnwnwnw +nenenwnwnenenenenenesewnenenenenene +nenwnwsewswwnwseenwnesenenwnenenwse +wwwwwwwwwwwwwwswwwwwe +seswswswswswnwsweswenwswswsewswswsw +swswnwwswswwwswwneewwwswsw +ewsewwnwnewwwwnwnwsewwwnwwnwse +eseeseeseeeeeseeeneeeeseswe +sweswswswswswswswwswswnwswseswswseswe +wnenwswwnwnwnwnww +sweeeseneseseneseseewseesesew +seneeswneneenenwwswwseenwneneewene +swswswswswsesweswswswswseseeseswswwswnw +seeseeeesenwsweeseeeseese +nwnwnwnwnwnwenwnwenwnwwnwnwnewenww +wswswwswswweswswswwswnewsewswsw +nwnwnwwnwnwnwnwwwwnwwnwnweenwnwnwwsw +eneeeeneenenweneneneesweewesw +nwsenwswnwnwnwnwnenenwnwnenenewnwnwnwnee +swweswswswswneneswswswsesesewswsesesese +swswsenwswswswswswnwneswsweswsewsesesew +eneeeeeeneeneeneneeeeeswee +swwseseswseswswnenwnwseswenenesenwswswsee +seseseseseneswneseseswswsesewsesesesenesese +swwswwswswwwswewwwwswswneswswsw +esewwswwwwwwswwsewswswwnwnwswswne +nwnwwnenwewnwnwnwnwswnwnwwswnwnewnw +newswwswwswswswwseswwswnewwnwswswse +wwwsenwnwwnwnwsenewwwwnwnwsenwnwwne +seswwnwwwnwswsweenwwwwwee +swswwswswswswswswswswswesenewswswswsw +wwswswswswswswswswswswswswswesw +wnwnwwwsewwwwnwwnwwnwwsenenwsew +sewnwnenewwnesenwneeenwnwnenwnw +nenwsenewnenwnenenenwnenenenenenenenenwne +swswswswswswswswswswseneswswseswswswswsw +neewnenenwnenenewnwnenesenenenwnenene +swneeeneneeeeweneesenw +eseewneeneeeseeswnewneeeeeeee +senewsewneewswseswneswswseseswseswsw +nenwnwenenenesweweswneneneneseeenene +sesesesewsesewseseweseneswnesesesesese +nenwnwnenenwnwnwswsenwnwneneswnenwsene +swswswwneswswswneswswswswswswswwswwswsw +wwwswsewwwnewnwwwwwwwnwew +nwwnwwnwwnwnwwwwnwwwswwnewwew +eenwneenweeswseneneneswesweneenenwe +nwwnwenwewnwwnwnwswnwwnwnenwsewwesw +seswswwswswnwswswswswswswsenenwseenenesw +eeneswenweeneeneeeneneeneeee +wwswswswwswswswwswswswswwwswswneswne +nenwnwnenenwnwnenenwnenenwsenwnenenwnwnw +nenenenenenenenenenewneneneneseneenenene +eswnwswswsweswswswswswswswswswnwswswsw +ewwwnwwnwswwnwwwwwnwnwnwwwnwenw +swswseswswswswswseseseswseneswswsewswsw +nwnenenwnwnenwnesenwnenwnenenenwnwnw +sewnwwwwsewwwswwswwswswnwneswwsw +swswswswswseswsenwsw +wseswewneseswseseswneeseeesesewne +seeewsweswswwswsewnenwneewewwnw +seswenesesweseeesesenwweewnesenw +swswswnwenwswsesewneswswneswseseeswswnw +nwnwnwnwnwnwnwnwnwnwnwnwsenwnw +nwewneneswneneneneenwswnwwesesenesenene +eeneneweneneeneneeswnewenenene +swwswswnwwsesweswwsweswnewwswwnw +enenewneweneneneneeenenenenenenene +eseesweseenweeeenweeseeeeeesw +nwneeeneseseseseseseswsewsewsesewse +nenewnweeeeswseswsesenw +wnenenenenwnwneneswnwseeswsesenwnwnenenee +eeeweeneeneseeesweeeneeenee +swwnewswnewwnewseswsweswwswswwwsw +senwnwseswwneswseseseswnwseseseseseseseswse +nwnwneswnwenwnwnwnwnwnwnwnwnwnwnenenenw +wnewnewnwswnwnwwwnwnwwnwwnwnwwsew +eeeeeeseeenwneeeewesesweese +swswseswswswseswswsweseswswneswswwnwsw +senwnwsenwnwswenenenwwenwenwnewnwnwnw +eweseswewseseneneseswneewseenwee +sesesesenweseseseseseseseesesesesewsesw +nwsenwnwnwnenwnwenwnww +newwweeswwnewnwseswseenewwnwswnew +wwsewwwwwwwwwwwwwwwnww +wwenwswsweeenweeeeeseeswnwe +nwswsewwnwwsenwswnwwnwsenewwnwenw +seewseeeseeeeneeeeeeeeese +enwswwnwwwnewwwsewnwewsenewswww +senwnwswsenwnwnwnwnenenwnwswnenwnwnwnwsw +swswwwswwnewwwwwwwewswseww +seswseswseesewseseswseseneseseseswsese +eneesenenwwnwseseeeenwneeenwswese +nenwnesenenwnenenwnwnewnwnwnwnwnenenene +swseseseswnwseswswseswswseswswswseswswsw +newnwswwwnwwwwswnwnwewwwnwww +neswsweeeeeenenenwswnenw +senwwnwnwnwnwwnwwnwnwnwnwnwnwnwenwnwne +nwnwnwnwnwnwnwnwnwnwnwnwnwnwwnwnwnwenw +seswwsewswwesweseseswneswswnwswnesw +nenwnwswswneneswneneneneeneswneneenenene +neeswnenenwneneneneneneneene +nwnwnwnwnwnwnwnwnwwwwnwnwenwwnwnwsenw +wwwwseswwwwenwnwswswwwswswswwsw +wwwwwwwwwwwwewwwewww +swswswswseswswswswswwswswswneswneswswswswse +nwnwenwswnwsenenwnwnwnwwnwnwnwnwnwswnw +nwseeneneneneneneeeeseeenewnenenenew +swneswneseseewesweneseenenewewnenene +enesenwnwseeeenwwweeseeswnwese +swswswswswneswswswswswswswswswswswswswsw +eeeeeswnweeeneneneeneeeeenene +eeseeseseswwnweeeeseseeseewsee +nwnwnwnwwnwnwnwnwnwnwnwnenwnwsenwnenwnwnw +enwwseseeeseseeeneseeeseenewsenwse +swneseseswsesesesesesesesesesesesesesese +eswewsenenwseeenwseenenenweswswnwew +eseswesesesesesweseseswwsenwnesesesene +nwnwswnwnwneswnwswnwsenwnwnwnwnwneeswnwe +swseswwneswneswswseswwswswswwneswese +wwswswwsenewwsewsenewnenewnesew +wseswnwswseeenwneeeeneeswsesenwesee +swesesenesweseewseeneseneseeseese +swnenesesenwseeswwswnwwnenwneneseswse +senwseswnewseeseweseseeeewewse +seeswseswwswneswswseneswseswseswswsww +wswwswswwwwswwswwswswwesw +seseeseneseseseeeneseseesewseswseese +seneswnwewswsesenwsenwneswswnewwswse +sweseeseseseseseseesesesenwseswnwsesesese +swnwswnewswswseswnewwnwswnewswswee +seenewwsenwwwwwwwnewsenewwsww +neswneswnenenenwswwenenwnenenenwenenwne +neneeeneneneswnwneneneweneeneswnenenene +seseseeseseenwsesee +nenenenenwnenwnwnwnenenewsenenenenenene +wwwweneneswnwesweweswnwsenwswnew +swnenwnwwenewnwnwnweneneenewneswnee +senesesewenwsesesesesesesesesesesesee +wswwnewewswswnwsweweseswwswswne +esweenweneneswnenene +seseseseswseseswesesesesesesesesesewse +nwnwnwnwseenwnwnwnwnwnwwwnwnwnwnwnwse +neneeeenweneeneneeeeesenenenee +esesenenewwseseseeeseeseneseeeesw +ewwnewwnwwsenwwnwnwswnwnwnwnwnwnw +nwnwnwnwnwnwnwnwnwnwswnwnwnwwenwnwnw +swnwnenwswewnwwnwnw +neneenesenewnenenewnenenenenenenenenene +swswsewsesweseseswseneswnw +seneneneneneswneneneeeeenwnenenenene +nwnewsenwnwenwnenwnwnwenwnwnenwnwnww +seneswnwsesesweswsenwnwweseneseswswse +nwwsenwwwenwwsenwsewswnweenwsenww +sewsesweeseneswnewseseseseswesenenesw +seswseswseseswswseseswswseseswseswsene +wwwwwwwwwwnwwewewwwwww +seswnwseseseeseese +swnweeeeeeeewseneeenweesww +seswsesenwsesenwsewswswswseeseswseeswsese +nwnwnwwnwnwwenwwwwwnwwnwwwnww +nenenewseneneneneneneswnenenenwnewsenenenw +nwwnwwnwnwnenwnwnwnwnwnwnwsewwnwnwnww +eneeeeseswesewnenwnwseswsewnwwnenwse +wenwsenwnwnenwnwwsewnwnwnwnwwsenwnww +nwseenwwsenewwenwsewewneenwnwnwsw +seneeswnwnesenwnwnwwesweswswnwnesenwnw +wwswswswswswwswwswwswswswneswsw +nwneneswenwswneneneswwsenwnesenenwnwnwnwne +wwsesenenenwnewnenenenenwneneseeene +nwsewwnwwesenwnwwnewnwwnwnwwwnw +seneneewneeneeneeneneneeenenenenenew +neswswsweswswswswnewneswwswwnwswwsw +seseseeseeswnweesewsesesenewnwse +senwwwwnwwwwnwwnwnwwwwwnww +swswswwswswswswswswswneswswswswswswswsw +neswswwenwnesenwneswnenwnenesewnenwnenene +enenenenenenenesweenenenenwnwenese +nwwwwwnwsewwwwwwwwwwwnww +nenenesenenwneneneenenenenee +nwenwnewswsewseewwwnwwe +nwnwnwnwnwnwewnwnwnwnwswnwsenwwnenwnwnw +swswswwswswswswswwswswnwswswswswesweswsw +seseeseseseseseseswsesesenwsesenw +wwwwnwsenwwwwwsenewnwnwwwww +eeeeeneeeeeenesweeeeneene +nwnenwnwnwwnewsewnesenwnwwwswwwww +wswnwwewseswswwnenewwseswswnewse +swseswswswswswswswswswswseswswswnwswnese +nenwswwnenwseeswnwnweswwnwnwnwne +nenwnwnenwnwwneneswnesenwnenwnwnenenwnw +eeeeeeeeeeneweee +swseseseseswswseeseswswswsenwswsesesw +eneeeeeweeeeneeneeeeesee +wseenwswswwswwwswweswseswnwnwwne +seseswswsesenwseseseseseswweswswswsese +nwwnwswwwnwwnwwewnewwsenwswnwnw +swwswswswsweesenwswswswwneswwswwswnwe +ewnwwwwseneswesewwenwwswswesw +seseesesenwseswseseesewsesesesesesese +swswswswneswneswswwswseswseseseseswswsw +wswswswnwseswswswswwswswsweswswwsw +nwnwnwnwnenwnenwswenwwswenenwnwnenwnw +swswswswswswwseswswseseswswneswswswsese +swswswwneswsweswwsewswwnwswwswswsww +nenewneneneswnwnwene +enweeeeeeeneeeeeswneeeswne +enenwneeeeeneeneeneneeeeeswsw +seseseseseswseseseseseseseseseenwsesesese +nwnwswwwnwwsenwwenww +eseseeseneseseseseseeeseewsesenwse +seseseseseswseswsenwswseswsenw +nwswseseseeseeenweeeseseeeeseee +nwwwwwwwseeswswewnwswsw +eseseseeseeseneseseeeeeweeesee +seenwsewseeeseswswseseseesenweesesee +neseweneenenenenenenenenwnenenenenwsw +swseewneswswswswswseseswswswseswsenwsw +swwneswswswswswswswseswwswswswswswwsw +wswswwwswweswsweswwnwswswswwwwww +wwwwwwswwswwnwwseswwewwwwnew +nwnwnwnwwnwwweswnwnwnwnwnwnwnwwnwnw +nenenenwseneswesewenewenenenwseenw +eenweeeesweeeeeeeeeenee +newswwnwswnenwwnwe +senwseswseneeseeseseenwwsenesesesenesew +eeeeeweeeeeeenweeseeseswsese +neneneneneewneneneneneeswnenwneseeese +enwswnwwnwneenwwnwnwnwnwnenwnwswnwnese +swnwseenwwwseeseesesese +seswwnenwwwnweeswenewnwswswnesee +seswsweswseswswseeswnesewenwwnwsesesw +nwsenwwnwnenenwwnwenesenwne +neeenwneseewneswnwnwsewseswneswwse +eseswsenesesweseeenwneesweneeee +wnenwseweneeswswneswsesenwseswneesesw +nwnenwsenenwnwnwseneswenwneswnwwnewne +eeneeseeewsweew +swwswnwswwwwswswwsewwwsewnesww +eeeeneweseeeeseneseseseeeweese +swnenwnewwswseneseswe +swnwswsewswnwweseswswseseseseswneneswwe +eneeseseswesenwsweseeeseneseesesese +neenenwnwneseneswwneenenesw +wwswwwwswwswwswswwwseswswwnew +seseseseeeeeeseseneeseseeeesewse +swseseswsweswnwseseseswseswseswseswnwsesw +swneswswnwswswswewwswswseswswnewswse +newnwsenwnwwwswwsewwneewwwsew +weneneeeeeeeneseeeneswwnenenene +wswswwswwwsewneswswwswswwwswswww +neneneneneneneneeneneneseneneneneswnewnene +sesesewsenwseswseneweseseneswswsenwse +swnwnenwswnwesenwnwwnwsenwnwwewenw +nwsewnenwnwnwnwnwnwnwwnwnesenwnwnwwwnw +nesweswwswseneswswnwseenwnwswsweseswsw +swneswwnenewseseeneenenenweneneesw +eseseseeseseeeeseseenweeeswsese +wwswwswswwswnwwwswwwwswswswswesw +ewwnwswnwwwwwwwwwsewwwww +seswnwseeswseswswseswsewswswswswsesesese +eesenwseeeseseseeseseseseeswneee +enwwwswwseswwswswwwwnwswwwswwww +nwnwwnwwwnwnwsewnwnwnwnwnwnwnwnwwnw +eeesesweseeseeeswneeesewenene +eeeeeseweseeeeseeseee +seseseseseeseseseeseseenwsenwseswswse +nwsenwnwnwsenwnwsenenwnwwnwnenwnwnwnwnw +senenesweneneswnwenenenenwnenenewwnenene +neweeweeseeneeneeseseeneeeeenw +wsenwnwnenwneeneseenwswsenene +seeeneneeenweneneeeenee +seeneeewseswnwseeseenwneseeeee +wweswwnwseewseswewswswnwnenw +nwwnwnwnwwwnwwnesewnwnewswseswne +swswswswwswsenwswsww +swwwsewwwwwwwnweewwnwwwe +wsewwwwwwwswwnwwwswwwwww +eeneeenweewsesweeeeneeneneenee +neneneneneneneseneeneswneswnewnenenenene +nenewsenwnewsewwseesewseneneswesee +nwnwnwnwnwnwnwnwnwnwnwsewnenwnwnwwnwnwnw +swwsewnenesewsweeseseswnesesesenwnese +nwwwswwwwswnewwwwwwwwwsene +sweeswswswnenwswswswnwswswswswswswwswsw +esesenenewwseneneseneenwswnewwewww +eseseneeseeseseseweseneeswesesese +swswswswnenwsesweseseseswswseswseseswseswse +eeeneneswneswneneeswswewenw +sesewnesewseseseseseseseneesesesesesese +seswswnesesesewswswseswneswnesesewswsese +neesewnwwswneswwswsewswwnww +eseewwseneswnewseneseseenwewswse +nwwnwwnwnwwswseenwwnwnwwwnwnwnwnw +wnwswwswwwnwwwnweneenwwswsewwnw +nwseseseseneeseseeseseseswsesesesesesese +nenwseeswnwwnwsenweswswswseese +nenenwnenwnenenwnwnenenenwswnenwnenwnene +enesenwswenwsesesenwswsenwsesesesenw +neneeeeeneseeenenwnenenenenenenee +sesesenewwseseseseswe +swseswnwswsewswswnwneeswswseewseseswswse +nwwnwnwnwwnwnwnwwnwwwnenwsewsewnwse +swnewneswwwsewswwnenenenwwewswwsw +swnwwnwsweeneeneeneeseseeneeeene +eeseewneneeseeeeeeeeseeweee +swswswswneseneswswwswwswseswseseneswswsw +senwnwnenwnwwnwnwnwnwswnwnwnwenwswnwnw +eeseseewseswneseneeenewsesesesenwse +swseswswswswseseswswswseseswswnesw +wwsenwnwsenwnenwnene +swswswsweswswswwswswswnwnewswseswswww +neneewswnenesweneesenwenewsweneseenw +swswseswsweneswnwwsenwswswse +nwsewsewwseneswnwwwswswwwwnwwww +nesesewseeseseseeseswseesesesesenwse +enenesenwsewswswnwseneeeeeeeeene +nenweneesesweeneeeneeeeeneene +wwswwwwwswswswnewswewwwenwsw +wwwwwswnwsewswwsewwwswwwnwsww +nesenenenewneneneneswswnenenenenenenenene +eeneeweesweeeeeeenesweew +swswswswseswseseneseswswseseswswseswsese +newnwswswswsweseswsww +nwswwnwsweswneswnwsenwnwsenenwneneee +wnwewswneswswswneweswwswwswswnweswsw +neswswswswswswwswewswswwswwswswswsw +swsewswswseswswswswswsweseswswswswswsw +nwwnwnwsewnenweswewnwwnwwswnwnww +swenenenenenenenwneneneneeswneneneenenw +wweswwwwswwswww +enweneenesweneneeeneeneeneneene +sesenewsenwseseseseswswswseseswswsenenesese +nenewneeswnesenwswnwnenwenwnwnwnw +neneswswnenenwswenwneeneseneneneewnww +neneeeneneenweeneeneneswneenenene +wwwwnwwwwwwswwwnwnwnewwww +swswswswwwnewwswwwwswwswwwww +nesweweneeeeeeeneweeeeene +nwnwnewnwnwnwsewnwwnwwnwwnwwswwww +wnwnwnwwwwswnwwwwnwew +senwnwnenwnwnwnwnwwnwnwnenwnwnwnwnwnenw +nwsewnenwnwnwnwnwnwnwnwnwwwnwwnwnwnwse +neswneseeswsweswneneenweeene +nenenwnwnwnenwnenenwnenwnwnwnweswnwsenwne +nwnwnewwnwnwnwwwswwnwnwnwwwwnwnw +seswwswswwswwswswswwswswwswswnwswsw +nwnwnwwnwsenwsenwnwsenwenwwnw +enwnwnwswnwsenwnwnenwnwenwsw +seneseswwswwesesenwewneenweseeewnw +swseesewewneesesenwnewseseseswsenw +nenwnwnenwnenwneenwsenenwnwnwnwnwnwnwwne +nwnwnenwnwnwwwnwwnwswnwnwwnwnwwww +seseseseseseseseseseswswsesesesesenesenwse +wswnwseseweeswseeneseeeneesesee +senewsweswseseseswsesesesesesese +neneneeeneeeneneeeenenweeneesw +nwnenenenenenenenenwswnenenenenenenenw +seseseseseseswsesewseseswsesenesw +eseeeeseseseeseseseseseesesewene +nwnwnwwnwnwnwnwnwwnwenwnwnwwnwwnwnw +seswseseenwswswwsesenwseeeeneesenesese +neeswseeseeeeeseeeeeeeseee diff --git a/data/advent24a.txt b/data/advent24a.txt new file mode 100644 index 0000000..55460d5 --- /dev/null +++ b/data/advent24a.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 \ No newline at end of file diff --git a/problems/day24.html b/problems/day24.html new file mode 100644 index 0000000..308e0c1 --- /dev/null +++ b/problems/day24.html @@ -0,0 +1,183 @@ + + + + +Day 24 - Advent of Code 2020 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 48*

   0xffff&2020

+ + + +
+ +

--- Day 24: Lobby Layout ---

Your raft makes it to the tropical island; it turns out that the small crab was an excellent navigator. You make your way to the resort.

+

As you enter the lobby, you discover a small problem: the floor is being renovated. You can't even reach the check-in desk until they've finished installing the new tile floor.

+

The tiles are all hexagonal; they need to be arranged in a hex grid with a very specific color pattern. Not in the mood to wait, you offer to help figure out the pattern.

+

The tiles are all white on one side and black on the other. They start with the white side facing up. The lobby is large enough to fit whatever pattern might need to appear there.

+

A member of the renovation crew gives you a list of the tiles that need to be flipped over (your puzzle input). Each line in the list identifies a single tile that needs to be flipped by giving a series of steps starting from a reference tile in the very center of the room. (Every line starts from the same reference tile.)

+

Because the tiles are hexagonal, every tile has six neighbors: east, southeast, southwest, west, northwest, and northeast. These directions are given in your list, respectively, as e, se, sw, w, nw, and ne. A tile is identified by a series of these directions with no delimiters; for example, esenee identifies the tile you land on if you start at the reference tile and then move one tile east, one tile southeast, one tile northeast, and one tile east.

+

Each time a tile is identified, it flips from white to black or from black to white. Tiles might be flipped more than once. For example, a line like esew flips a tile immediately adjacent to the reference tile, and a line like nwwswee flips the reference tile itself.

+

Here is a larger example:

+
sesenwnenenewseeswwswswwnenewsewsw
+neeenesenwnwwswnenewnwwsewnenwseswesw
+seswneswswsenwwnwse
+nwnwneseeswswnenewneswwnewseswneseene
+swweswneswnenwsewnwneneseenw
+eesenwseswswnenwswnwnwsewwnwsene
+sewnenenenesenwsewnenwwwse
+wenwwweseeeweswwwnwwe
+wsweesenenewnwwnwsenewsenwwsesesenwne
+neeswseenwwswnwswswnw
+nenwswwsewswnenenewsenwsenwnesesenew
+enewnwewneswsewnwswenweswnenwsenwsw
+sweneswneswneneenwnewenewwneswswnese
+swwesenesewenwneswnwwneseswwne
+enesenwswwswneneswsenwnewswseenwsese
+wnwnesenesenenwwnenwsewesewsesesew
+nenewswnwewswnenesenwnesewesw
+eneswnwswnwsenenwnwnwwseeswneewsenese
+neswnwewnwnwseenwseesewsenwsweewe
+wseweeenwnesenwwwswnew
+
+

In the above example, 10 tiles are flipped once (to black), and 5 more are flipped twice (to black, then back to white). After all of these instructions have been followed, a total of 10 tiles are black.

+

Go through the renovation crew's list and determine which tiles they need to flip. After all of the instructions have been followed, how many tiles are left with the black side up?

+
+

Your puzzle answer was 538.

--- Part Two ---

The tile floor in the lobby is meant to be a living art exhibit. Every day, the tiles are all flipped according to the following rules:

+
    +
  • Any black tile with zero or more than 2 black tiles immediately adjacent to it is flipped to white.
  • +
  • Any white tile with exactly 2 black tiles immediately adjacent to it is flipped to black.
  • +
+

Here, tiles immediately adjacent means the six tiles directly touching the tile in question.

+

The rules are applied simultaneously to every tile; put another way, it is first determined which tiles need to be flipped, then they are all flipped at the same time.

+

In the above example, the number of black tiles that are facing up after the given number of days has passed is as follows:

+
Day 1: 15
+Day 2: 12
+Day 3: 25
+Day 4: 14
+Day 5: 23
+Day 6: 28
+Day 7: 41
+Day 8: 37
+Day 9: 49
+Day 10: 37
+
+Day 20: 132
+Day 30: 259
+Day 40: 406
+Day 50: 566
+Day 60: 788
+Day 70: 1106
+Day 80: 1373
+Day 90: 1844
+Day 100: 2208
+
+

After executing this process a total of 100 times, there would be 2208 black tiles facing up.

+

How many tiles will be black after 100 days?

+
+

Your puzzle answer was 4259.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file diff --git a/stack.yaml b/stack.yaml index 021f4ba..0c9524d 100644 --- a/stack.yaml +++ b/stack.yaml @@ -58,6 +58,7 @@ packages: - advent21 - advent22 - advent23 +- advent24 # Dependency packages to be pulled from upstream that are not in the resolver. # These entries can reference officially published versions as well as