X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=src%2Fadvent10%2Fadvent10.hs;h=19b1f7090aac7c3194cefd2b29df3eff95913f5a;hb=8227e18e534ac192b718bbfe0592e81a30f2a433;hp=59d7c47875e5417d3086cc48831a9b4e0e696048;hpb=7bc0f0ba5aeeecd90f6b7ca546d1b330f56f2996;p=advent-of-code-18.git diff --git a/src/advent10/advent10.hs b/src/advent10/advent10.hs index 59d7c47..19b1f70 100644 --- a/src/advent10/advent10.hs +++ b/src/advent10/advent10.hs @@ -12,7 +12,6 @@ import Text.Megaparsec.Char import qualified Text.Megaparsec.Char.Lexer as L import qualified Control.Applicative as CA -import qualified Data.Map.Strict as M import qualified Data.Set as S type Coord = (Integer, Integer) -- x, y @@ -30,13 +29,14 @@ main = do print time -part1 particles - | area' > area = showParticles particles - | otherwise = part1 particles' - where particles' = updateAll particles - area = boundsArea particles - area' = boundsArea particles' +-- part1 particles +-- | area' > area = showParticles particles +-- | otherwise = part1 particles' +-- where particles' = updateAll particles +-- area = boundsArea particles +-- area' = boundsArea particles' +part2 :: Integer -> [Particle] -> (Integer, String) part2 time particles | area' > area = (time, showParticles particles) | otherwise = part2 (time+1) particles' @@ -78,8 +78,8 @@ showParticles particles = intercalate "\n" rows showCell :: Integer -> Integer -> Grid -> Char showCell x y grid - | (x, y) `S.member` grid = '*' - | otherwise = ' ' + | (x, y) `S.member` grid = '\x2593' + | otherwise = '\x2591' showRow :: Integer -> Integer -> Integer -> Grid -> String showRow y minX maxX grid = [showCell x y grid | x <- [minX..maxX] ] @@ -106,8 +106,8 @@ particleFileP = many particleP particleP = particlify <$> positionP <*> velocityP where particlify x v = Particle x v -positionP = posPrefix *> pairP <* suffix -velocityP = velPrefix *> pairP <* suffix +positionP = between posPrefix suffix pairP +velocityP = between velPrefix suffix pairP pairP = (,) <$> signedInteger <* commaP <*> signedInteger