Skip to content

Commit

Permalink
Optimise imports
Browse files Browse the repository at this point in the history
And migrate affected classes to the newer `Challenge` format.
  • Loading branch information
FWDekker committed Dec 19, 2024
1 parent fefbf0e commit b9526ea
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 48 deletions.
6 changes: 3 additions & 3 deletions aoc/src/main/kotlin/com/fwdekker/aoc/y2023/Day23.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import com.fwdekker.std.grid.north
import com.fwdekker.std.grid.south
import com.fwdekker.std.grid.toChart
import com.fwdekker.std.grid.west
import com.fwdekker.std.read
import java.util.PriorityQueue


class Day23(resource: String = resource(2023, 23)) : Day() {
private val chart = read(resource).toChart()
// See https://adventofcode.com/2023/day/23
class Day23(sample: Int? = null) : Day(year = 2023, day = 23, sample = sample) {
private val chart = input.toChart()

private val start = Coords(0, chart.firstRow.indexOf('.'))
private val end = Coords(chart.lastRowIndex, chart.lastRow.indexOf('.'))
Expand Down
5 changes: 2 additions & 3 deletions aoc/src/main/kotlin/com/fwdekker/aoc/y2024/Day13.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import com.fwdekker.std.collections.map
import com.fwdekker.std.collections.mapThirds
import com.fwdekker.std.collections.seconds
import com.fwdekker.std.maths.plus
import com.fwdekker.std.read
import java.math.BigInteger
import java.math.MathContext
import java.math.RoundingMode


// See https://adventofcode.com/2024/day/13
class Day13(resource: String = resource(2024, 13)) : Day() {
class Day13(sample: Int? = null) : Day(year = 2024, day = 13, sample = sample) {
private val mc = MathContext.DECIMAL128
private val machines = read(resource)
private val machines = input
.let { file -> Regex("\\d+").findAll(file).map { it.value.toBigInteger() } }
.chunked(6)
.map { machine -> machine.chunked(2).map { it.asPair() }.asTriple() }
Expand Down
6 changes: 3 additions & 3 deletions aoc/src/main/kotlin/com/fwdekker/aoc/y2024/Day2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.fwdekker.aoc.y2024
import com.fwdekker.aoc.Day
import com.fwdekker.std.collections.without
import com.fwdekker.std.linesNotBlank
import com.fwdekker.std.read
import com.fwdekker.std.toInts
import kotlin.math.absoluteValue
import kotlin.math.sign


class Day2(resource: String = resource(2024, 2)) : Day() {
private val reports = read(resource).linesNotBlank().toInts(' ')
// See https://adventofcode.com/2024/day/2
class Day2(sample: Int? = null) : Day(year = 2024, day = 2, sample = sample) {
private val reports = input.linesNotBlank().toInts(' ')


override fun part1(): Int = reports.count { it.isSafe() }
Expand Down
19 changes: 8 additions & 11 deletions aoc/src/test/kotlin/com/fwdekker/aoc/y2023/Day23Test.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.fwdekker.aoc.y2023

import com.fwdekker.aoc.Day
import com.fwdekker.aoc.Day.Companion.resource
import com.fwdekker.aoc.DayTest
import com.fwdekker.std.ChallengeTest
import com.fwdekker.std.case
import io.kotest.core.annotation.Tags


/**
* Tests for [Day23].
*/
object Day23Test : DayTest(
@Tags("2023")
object Day23Test : ChallengeTest(
::Day23,
listOf(
Triple(resource(2023, 23, sample = 1), Day::part1, 94),
Triple(resource(2023, 23, sample = 1), Day::part2, 154),
Triple(resource(2023, 23), Day::part1, 2318),
Triple(resource(2023, 23), Day::part2, 6426),
case(part = 1, sample = 1) to 94,
case(part = 2, sample = 1) to 154,
case(part = 1) to 2318,
case(part = 2) to 6426,
)
)
18 changes: 8 additions & 10 deletions aoc/src/test/kotlin/com/fwdekker/aoc/y2024/Day13Test.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.fwdekker.aoc.y2024

import com.fwdekker.aoc.Day
import com.fwdekker.aoc.DayTest
import io.kotest.core.annotation.Ignored
import com.fwdekker.std.ChallengeTest
import com.fwdekker.std.case
import io.kotest.core.annotation.Tags
import java.math.BigInteger


/**
* Tests for [Day13].
*/
object Day13Test : DayTest(
@Tags("2024")
object Day13Test : ChallengeTest(
::Day13,
listOf(
Triple(Day.resource(2024, 13, sample = 1), Day::part1, BigInteger("480")),
Triple(Day.resource(2024, 13), Day::part1, BigInteger("29517")),
Triple(Day.resource(2024, 13), Day::part2, BigInteger("103570327981381")),
case(part = 1, sample = 1) to BigInteger("480"),
case(part = 1) to BigInteger("29517"),
case(part = 2) to BigInteger("103570327981381"),
)
)
1 change: 0 additions & 1 deletion aoc/src/test/kotlin/com/fwdekker/aoc/y2024/Day19Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.fwdekker.aoc.y2024

import com.fwdekker.std.ChallengeTest
import com.fwdekker.std.case
import io.kotest.core.annotation.Ignored
import io.kotest.core.annotation.Tags


Expand Down
18 changes: 8 additions & 10 deletions aoc/src/test/kotlin/com/fwdekker/aoc/y2024/Day2Test.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.fwdekker.aoc.y2024

import com.fwdekker.aoc.Day
import com.fwdekker.aoc.DayTest
import com.fwdekker.std.ChallengeTest
import com.fwdekker.std.case
import io.kotest.core.annotation.Tags


/**
* Tests for [Day2].
*/
object Day2Test : DayTest(
@Tags("2024")
object Day2Test : ChallengeTest(
::Day2,
listOf(
Triple(Day.resource(2024, 2, sample = 1), Day::part1, 2),
Triple(Day.resource(2024, 2, sample = 1), Day::part2, 4),
Triple(Day.resource(2024, 2), Day::part1, 334),
Triple(Day.resource(2024, 2), Day::part2, 400),
case(part = 1, sample = 1) to 2,
case(part = 2, sample = 1) to 4,
case(part = 1) to 334,
case(part = 2) to 400,
)
)
2 changes: 1 addition & 1 deletion euler
Submodule euler updated from 5d42a5 to ddde77
17 changes: 11 additions & 6 deletions std/src/test/kotlin/com/fwdekker/std/ChallengeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ abstract class ChallengeTest(
val (part, sample) = input
challenge(sample).runPart(part) shouldBe expected
}
})

/**
* A test case for [ChallengeTest].
*/
fun case(part: Int = 1, sample: Int? = null): Pair<Int, Int?> = Pair(part, sample)
}) {
/**
* Holds constants.
*/
companion object {
/**
* A test case for [ChallengeTest].
*/
fun case(part: Int = 1, sample: Int? = null): Pair<Int, Int?> = Pair(part, sample)
}
}

0 comments on commit b9526ea

Please sign in to comment.