Skip to content

Commit 2d5c72e

Browse files
authored
feat: add day 1 and 2 solution and format (#573)
1 parent 52bf3f3 commit 2d5c72e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/2024/puzzles/day01.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ end part2
7777
- [Solution](https://scastie.scala-lang.org/Sporarum/jVlQBCvoQXCtlK4ryIn42Q/4) by [Quentin Bernet](https://github.com/Sporarum)
7878
- [Solution](https://github.com/jnclt/adventofcode2024/blob/main/day01/historian-hysteria.sc) by [jnclt](https://github.com/jnclt)
7979
- [Solution](https://github.com/YannMoisan/advent-of-code/blob/master/2024/src/main/scala/Day1.scala) by [YannMoisan](https://github.com/YannMoisan)
80+
- [Solution](https://github.com/itsjoeoui/aoc2024/blob/main/src/day01.scala) by [itsjoeoui](https://github.com/itsjoeoui)
8081

8182
Share your solution to the Scala community by editing this page.
8283
You can even write the whole article! [See here for the expected format](https://github.com/scalacenter/scala-advent-of-code/discussions/424)

docs/2024/puzzles/day02.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ We need to check consecutive pairs of numbers in each report in 3 ways:
3939
- to see if their differences are within given bounds.
4040

4141
So let's construct them only once, save it as a `val`, then reuse this value 3 times.
42-
It's not the most efficient way (like traversing only once and keeping track of everything),
42+
It's not the most efficient way (like traversing only once and keeping track of everything),
4343
but it's very clean and simple:
4444

4545
```scala
@@ -61,7 +61,7 @@ def part1(input: String): Int = parse(input).count(_.isSafe)
6161

6262
### Part 2
6363

64-
Now we add new methods to `Report`.
64+
Now we add new methods to `Report`.
6565
We check if there exists a `Report` obtained by dropping one number, such that it's safe.
6666
We do this by iterating over the index of each `Report`.
6767
Then, a `Report` is safe, if it's safe as in Part 1, or one of the dampened reports is safe:
@@ -75,8 +75,8 @@ case class Report(levels: Seq[Long]):
7575
def isDampenedSafe: Boolean = isSafe || checkDampenedReports
7676
```
7777

78-
Again this is not the most efficient way (we are creating many new `Report` instances),
79-
but our puzzle inputs are fairly short (there are at most 8 levels in each `Report`),
78+
Again this is not the most efficient way (we are creating many new `Report` instances),
79+
but our puzzle inputs are fairly short (there are at most 8 levels in each `Report`),
8080
so it's a simple approach that reuses the `isSafe` method from Part 1.
8181

8282
Part 2 solver now counts the dampened safe reports:
@@ -95,6 +95,7 @@ def part2(input: String): Int = parse(input).count(_.isDampenedSafe)
9595
- [Solution](https://github.com/Philippus/adventofcode/blob/main/src/main/scala/adventofcode2024/Day02.scala) by [Philippus Baalman](https://github.com/philippus)
9696

9797
- [Solution](https://github.com/nikiforo/aoc24/blob/main/src/main/scala/io/github/nikiforo/aoc24/D2T2.scala) by [Artem Nikiforov](https://github.com/nikiforo)
98+
- [Solution](https://github.com/itsjoeoui/aoc2024/blob/main/src/day02.scala) by [itsjoeoui](https://github.com/itsjoeoui)
9899

99100
Share your solution to the Scala community by editing this page.
100101
You can even write the whole article! [See here for the expected format](https://github.com/scalacenter/scala-advent-of-code/discussions/424)

0 commit comments

Comments
 (0)