Skip to content

Commit

Permalink
2024 Day 02
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Dec 2, 2024
1 parent c7ad56f commit 34608bb
Show file tree
Hide file tree
Showing 9 changed files with 1,118 additions and 45 deletions.
14 changes: 7 additions & 7 deletions 2024/d01/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ const part1 = (data: ReadonlyArray<[number, number]>): number => {
}

const part2 = (data: ReadonlyArray<[number, number]>): number => {
const rightCounts = counting(data.map(item => item[1]), item => item)
const rightCounts = counting(
data.map(item => item[1]),
item => item,
)
const similiarityScores = data.map(item => (rightCounts[item[0]] ?? 0) * item[0])

return sum(similiarityScores)
}

Expand All @@ -24,12 +27,9 @@ const reader = (file: string): ReadonlyArray<[number, number]> => {
.map(line => {
const match = line.match(/(\d+)\s+(\d+)/)

return [
parseInt(match[1], 10),
parseInt(match[2], 10)
] as [number, number]
return [parseInt(match[1], 10), parseInt(match[2], 10)] as [number, number]
})
}

testRuns('01', reader, part1, part2)
solutionRuns('01', reader, part1, part2)
solutionRuns('01', reader, part1, part2)
Loading

0 comments on commit 34608bb

Please sign in to comment.