Skip to content

Commit

Permalink
Merge pull request #36 from ephemient/kt/day4
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient authored Dec 4, 2024
2 parents 77e7fb8 + 8ea9827 commit a6ef04b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.github.ephemient.aoc2024

class Day4(
input: String,
) {
class Day4(input: String) {
private val lines = input.lines()

fun part1() = lines.indices.sumOf { y ->
lines[y].indices.sumOf { x ->
Direction.entries.count { (dx, dy) ->
"XMAS".withIndex().all { (i, c) ->
XMAS.withIndex().all { (i, c) ->
lines.getOrNull(y + i * dy)?.getOrNull(x + i * dx) == c
}
}
Expand All @@ -20,12 +18,8 @@ class Day4(
if (lines[y][x] != 'A') return@count false
val n = lines.getOrNull(y - 1) ?: return@count false
val s = lines.getOrNull(y + 1) ?: return@count false
val nw = n.getOrNull(x - 1) ?: return@count false
val ne = n.getOrNull(x + 1) ?: return@count false
val sw = s.getOrNull(x - 1) ?: return@count false
val se = s.getOrNull(x + 1) ?: return@count false
(nw == 'M' && se == 'S' || se == 'M' && nw == 'S') &&
(sw == 'M' && ne == 'S' || ne == 'M' && sw == 'S')
setOf(n.getOrNull(x - 1), s.getOrNull(x + 1)) == MS &&
setOf(n.getOrNull(x + 1), s.getOrNull(x - 1)) == MS
}
}

Expand All @@ -43,4 +37,9 @@ class Day4(
operator fun component1() = dx
operator fun component2() = dy
}

companion object {
private const val XMAS = "XMAS"
private val MS = "MS".toSet()
}
}
2 changes: 1 addition & 1 deletion kt/graalvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val externalTestClasspath = configurations.resolvable("externalTestClasspath") {
configurations.testImplementation {
extendsFrom(externalTestClasses.get())
}
tasks.named<Test>("test") {
tasks.test {
testClassesDirs = files(testClassesDirs, externalTestClasspath.get())
useJUnitPlatform()
}
Expand Down

0 comments on commit a6ef04b

Please sign in to comment.