Skip to content

Commit

Permalink
[2024/3] Mull It Over (Part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfolta committed Dec 3, 2024
1 parent e6391d2 commit 5643c24
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
| 2021 |||||||||||| ||| | | | | | | | | | | | 26 |
| 2022 |||||||||||||| | | | | | | || | | || 28 |
| 2023 |||||||| | | | | | | | | | | | | | | | | | | 12 |
| 2024 ||| | | | | | | | | | | | | | | | | | | | | | | | 5 |
| 2024 ||| | | | | | | | | | | | | | | | | | | | | | | | 6 |

## 🛷 How to run

Expand Down Expand Up @@ -164,7 +164,7 @@ e.g. `HandyHaversacks`)*
| | 7 | [Camel Cards](https://adventofcode.com/2023/day/7) | [[Code](src/main/kotlin/adventofcode/year2023/Day07CamelCards.kt)] [[Test](src/test/kotlin/adventofcode/year2023/Day07CamelCardsSpec.kt)] | `250474325` | |
| [**2024**](https://adventofcode.com/2024) | 1 | [Historian Hysteria](https://adventofcode.com/2024/day/1) | [[Code](src/main/kotlin/adventofcode/year2024/Day01HistorianHysteria.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day01HistorianHysteriaSpec.kt)] | `1970720` | `17191599` |
| | 2 | [Red-Nosed Reports](https://adventofcode.com/2024/day/2) | [[Code](src/main/kotlin/adventofcode/year2024/Day02RedNosedReports.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day02RedNosedReportsSpec.kt)] | `572` | `612` |
| | 3 | [Mull It Over](https://adventofcode.com/2024/day/3) | [[Code](src/main/kotlin/adventofcode/year2024/Day03MullItOver.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day03MullItOverSpec.kt)] | `174960292` | |
| | 3 | [Mull It Over](https://adventofcode.com/2024/day/3) | [[Code](src/main/kotlin/adventofcode/year2024/Day03MullItOver.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day03MullItOverSpec.kt)] | `174960292` | `56275602` |

## 🕯️ Useful commands

Expand Down
20 changes: 15 additions & 5 deletions src/main/kotlin/adventofcode/year2024/Day03MullItOver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ import adventofcode.Puzzle
import adventofcode.PuzzleInput

class Day03MullItOver(customInput: PuzzleInput? = null) : Puzzle(customInput) {
override fun partOne() =
mulRegex
.findAll(input)
.map { it.destructured }
.sumOf { (x, y) -> x.toInt() * y.toInt() }
override fun partOne() = input.sumOfMultiplications()

override fun partTwo() =
input
.split(doRegex)
.map { doPart -> doPart.split(dontRegex).first() }
.sumOf { it.sumOfMultiplications() }

companion object {
private val mulRegex = """mul\((\d{1,3}),(\d{1,3})\)""".toRegex()
private val doRegex = """do\(\)""".toRegex()
private val dontRegex = """don't\(\)""".toRegex()

private fun String.sumOfMultiplications() =
mulRegex
.findAll(this)
.map { it.destructured }
.sumOf { (x, y) -> x.toInt() * y.toInt() }
}
}
5 changes: 4 additions & 1 deletion src/test/kotlin/adventofcode/year2024/Day03MullItOverSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package adventofcode.year2024

import adventofcode.PuzzleBaseSpec

class Day03MullItOverSpec : PuzzleBaseSpec(161)
class Day03MullItOverSpec : PuzzleBaseSpec(
listOf("xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))" to 161),
listOf("xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))" to 48),
)
1 change: 0 additions & 1 deletion src/test/resources/inputs/year2024/day03.txt

This file was deleted.

0 comments on commit 5643c24

Please sign in to comment.