Skip to content

Commit

Permalink
test case
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 3, 2023
1 parent dca69bd commit b082318
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion solutions/src/2023/03.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ Maintainer : emertens@gmail.com
<https://adventofcode.com/2023/day/3>
>>> :{
:main +
"467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598.."
:}
4361
467835
-}
module Main where

Expand All @@ -19,7 +35,7 @@ import Data.List (find)
import Advent (getInputMap)
import Advent.Coord (Coord, left, neighbors, right)

-- |
-- | Parse the input schematic and print answers to both parts.
--
-- >>> :main
-- 527144
Expand All @@ -30,6 +46,7 @@ main =
let
lkp i = Map.findWithDefault '.' i input

-- Map of each part in the schematic to the list of adjacent part numbers
partMap :: Map Coord [Int]
partMap = Map.fromListWith (++)
[ (part, [read (map lkp cs)])
Expand All @@ -43,5 +60,6 @@ main =
print (sum (fmap sum partMap))
print (sum [a * b | (c, [a,b]) <- Map.assocs partMap, '*' == lkp c])

-- | Things that aren't digits or periods.
isSymbol :: Char -> Bool
isSymbol x = not (isDigit x) && x /= '.'

0 comments on commit b082318

Please sign in to comment.