Skip to content

Commit

Permalink
Day3 very small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimitroulas committed Dec 4, 2023
1 parent b4c6506 commit 7127509
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 3 additions & 6 deletions src/Solutions/Day03.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ parser = fmap (V.map combineNumbers) . P.parseOnly (V.fromList <$> linesOf (V.fr

part1 :: Input -> Int
part1 input =
sum $
map (\(Number x) -> x) $
catMaybes $
removeConseqDups $
map (Matrix.! input) $
getPartNumberPositions input
let partNumberPositions = getPartNumberPositions input
partNumbers = map getNumberVal $ catMaybes $ removeConseqDups $ map (Matrix.! input) partNumberPositions
in sum partNumbers

schematicItemParser :: P.Parser (Maybe SchematicItem)
schematicItemParser =
Expand Down
14 changes: 7 additions & 7 deletions test/Day03.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ test_day03 = testGroup "Day03"
testCase "part 1 - example input" $ do
part1 <$> parser exampleInput @?= Right 4361,

-- testCase "part 1" $ do
-- input <- parser <$> readFile "data/day02.txt"
-- part1 <$> input @?= Right 2632,
testCase "part 1" $ do
input <- parser <$> readFile "data/day03.txt"
part1 <$> input @?= Right 525181,

testCase "part 2 - example input" $ do
part2 <$> parser exampleInput @?= Right 467835
part2 <$> parser exampleInput @?= Right 467835,

-- testCase "part 2" $ do
-- input <- parser <$> readFile "data/day02.txt"
-- part2 <$> input @?= Right 69629
testCase "part 2" $ do
input <- parser <$> readFile "data/day03.txt"
part2 <$> input @?= Right 84289137
]

0 comments on commit 7127509

Please sign in to comment.