Skip to content

Commit

Permalink
Solved riddle for AoC 2024 day 4 part 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gentleman1983 committed Dec 4, 2024
1 parent 57546d9 commit 553398b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To run all solutions, simply run `./gradlew run`. If you want to run the solutio
## Contributions:
| Year | Language(s) | Total Stars | Link to repository |
|---------|--------------------------------------------------------------|------------:|------------------------------------------------------------------------------------|
| 2024 | Kotlin ![Kotlin](img/kotlin.png) | 6 / 50 ⭐ | [aoc2024](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2024) |
| 2024 | Kotlin ![Kotlin](img/kotlin.png) | 8 / 50 ⭐ | [aoc2024](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2024) |
| 2023 | Java ![Java](img/java.png), Kotlin ![Kotlin](img/kotlin.png) | 50 / 50 ⭐ | [aoc2023](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2023) |
| 2022 | Java ![Java](img/java.png), Kotlin ![Kotlin](img/kotlin.png) | 50 / 50 ⭐ | [aoc2022](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2022) |
| 2022 | Kotlin ![Kotlin](img/kotlin.png) | 2 / 2 ⭐ | [meilisearch](https://github.com/Gentleman1983/advent-of-code/tree/main/meili2022) |
Expand All @@ -28,5 +28,5 @@ To run all solutions, simply run `./gradlew run`. If you want to run the solutio
| 2017 | Java ![Java](img/java.png), Kotlin ![Kotlin](img/kotlin.png) | 50 / 50 ⭐ | [aoc2017](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2017) |
| 2016 | Java ![Java](img/java.png), Kotlin ![Kotlin](img/kotlin.png) | 50 / 50 ⭐ | [aoc2016](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2016) |
| 2015 | Java ![Java](img/java.png), Kotlin ![Kotlin](img/kotlin.png) | 50 / 50 ⭐ | [aoc2015](https://github.com/Gentleman1983/advent-of-code/tree/main/aoc2015) |
| **SUM** | | **458** | |
| **SUM** | | **460** | |

6 changes: 3 additions & 3 deletions aoc2024/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more information see https://adventofcode.com [2024](https://adventofcode.co
| 1 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 2 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 3 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 4 | ![Kotlin](../img/kotlin.png) | ![Kotlin](../img/kotlin.png) |
| 4 | ![Kotlin](../img/kotlin.png) | ![Kotlin](../img/kotlin.png) |
| 5 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 6 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 7 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
Expand All @@ -35,9 +35,9 @@ For more information see https://adventofcode.com [2024](https://adventofcode.co
| 23 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 24 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| 25 |![Kotlin](../img/kotlin.png) |![Kotlin](../img/kotlin.png) |
| **SUM** | **3** | **3** |
| **SUM** | **4** | **4** |

Total: 6
Total: 8

## Solution image
N/A
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,23 @@ class CeresSearch(private var filename: String) {
}

fun processPart2(): Any =
0L
data
.indices
.sumOf { y ->
data[y]
.indices
.count { x ->
if (data[y][x] != 'A') {
return@count false
}

val n = data.getOrNull(y - 1) ?: return@count false
val s = data.getOrNull(y + 1) ?: return@count false

setOf(n.getOrNull(x - 1), s.getOrNull(x + 1)) == MS &&
setOf(n.getOrNull(x + 1), s.getOrNull(x - 1)) == MS
}
}

private fun getResourceAsText(path: String): List<String> =
this
Expand All @@ -37,5 +53,6 @@ class CeresSearch(private var filename: String) {

companion object {
private const val XMAS = "XMAS"
private val MS = setOf('M', 'S')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CeresSearchTest {
@JvmStatic
private fun getDataForTestProcessPart2(): Stream<Arguments> =
Stream.of(
Arguments.of("de/havox_design/aoc2024/day04/day04part2sample.txt", 9)
Arguments.of("de/havox_design/aoc2024/day04/day04sample.txt", 9)
)
}
}

0 comments on commit 553398b

Please sign in to comment.