-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
178 additions
and
228 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
plugins { | ||
kotlin("jvm") version "1.9.21" | ||
id("org.jetbrains.dokka") version "1.9.10" | ||
application | ||
} | ||
|
||
application { | ||
mainClass.set("be.amedee.adventofcode.AppKt") | ||
} | ||
|
||
group = "be.amedee" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(kotlin("stdlib")) | ||
testImplementation("org.jetbrains.kotlin:kotlin-test") | ||
testImplementation("io.kotest:kotest-core:4.1.3") | ||
testImplementation("io.kotest:kotest-assertions-core:5.6.2") | ||
testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events("skipped", "passed", "failed") | ||
showStandardStreams = true | ||
} | ||
} | ||
|
||
tasks.named("run") { | ||
dependsOn(tasks.test) | ||
group = "application" | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(21) | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/groovy/be/amedee/adventofcode/aoc2015/day01/Day01.groovy
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package be.amedee.adventofcode | ||
|
||
import be.amedee.adventofcode.aoc2015.day01.Day01 | ||
|
||
fun main() { | ||
val day01 = Day01() | ||
day01.main() | ||
} |
64 changes: 33 additions & 31 deletions
64
src/main/kotlin/be/amedee/adventofcode/aoc2015/day01/Day01.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
package be.amedee.adventofcode.aoc2015.day01 | ||
|
||
fun readStringFromResource(filePath: String) = {}.javaClass.classLoader.getResource(filePath)?.readText() | ||
|
||
fun findFloorAndBasementPosition(instructions: String): Pair<Int, Int> { | ||
var floor = 0 | ||
var basementPosition = -1 | ||
|
||
for ((index, char) in instructions.withIndex()) { | ||
when (char) { | ||
'(' -> floor++ | ||
')' -> { | ||
floor-- | ||
if (floor == -1 && basementPosition == -1) { | ||
basementPosition = index + 1 // Adjust index to start from 1 | ||
} | ||
} | ||
/** | ||
* Santa is trying to deliver presents in a large apartment building, | ||
* but he can't find the right floor - the directions he got are a little confusing. | ||
*/ | ||
class Day01 { | ||
|
||
/** | ||
* Single move to the next floor, up or down. | ||
* | ||
* @param instruction a single elevator instruction | ||
* @return do we go up or down | ||
*/ | ||
val move: (String) -> Int = { | ||
when (it) { | ||
"(" -> 1 | ||
")" -> -1 | ||
else -> 0 | ||
} | ||
} | ||
|
||
return Pair(floor, basementPosition) | ||
} | ||
|
||
fun main() { | ||
// Specify the file path | ||
val filePath = "be/amedee/adventofcode/aoc2015/day01/input" | ||
|
||
val puzzleInput: String = readStringFromResource(filePath)!! | ||
|
||
val (floor, basementPosition) = findFloorAndBasementPosition(puzzleInput) | ||
/** | ||
* The entire list of elevator instructions. | ||
* | ||
* @param instructions the list of elevator instructions, Lisp-style | ||
* @return at which floor Santa ends up | ||
*/ | ||
val followInstructions: (String) -> Int = { instructionList -> | ||
instructionList | ||
.toList() | ||
.sumOf { move(it.toString()) } | ||
} | ||
|
||
println("Santa ends up on floor $floor.") | ||
fun main() { | ||
val filePath = "be/amedee/adventofcode/aoc2015/day01/input" | ||
val puzzleInput: String = readStringFromResource(filePath)!! | ||
|
||
if (basementPosition != -1) { | ||
println("Santa enters the basement at character position $basementPosition.") | ||
} else { | ||
println("Santa never enters the basement.") | ||
val endFloor = followInstructions(puzzleInput) | ||
println("Santa ends up on floor $endFloor.") | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/be/amedee/adventofcode/aoc2015/day01/Day01SecondAttempt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package be.amedee.adventofcode.aoc2015.day01 | ||
|
||
fun readStringFromResource(filePath: String) = {}.javaClass.classLoader.getResource(filePath)?.readText() | ||
|
||
fun findFloorAndBasementPosition(instructions: String): Pair<Int, Int> { | ||
var floor = 0 | ||
var basementPosition = -1 | ||
|
||
for ((index, char) in instructions.withIndex()) { | ||
when (char) { | ||
'(' -> floor++ | ||
')' -> { | ||
floor-- | ||
if (floor == -1 && basementPosition == -1) { | ||
basementPosition = index + 1 // Adjust index to start from 1 | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Pair(floor, basementPosition) | ||
} | ||
|
||
fun main() { | ||
// Specify the file path | ||
val filePath = "be/amedee/adventofcode/aoc2015/day01/input" | ||
|
||
val puzzleInput: String = readStringFromResource(filePath)!! | ||
|
||
val (floor, basementPosition) = findFloorAndBasementPosition(puzzleInput) | ||
|
||
println("Santa ends up on floor $floor.") | ||
|
||
if (basementPosition != -1) { | ||
println("Santa enters the basement at character position $basementPosition.") | ||
} else { | ||
println("Santa never enters the basement.") | ||
} | ||
|
||
} |
68 changes: 0 additions & 68 deletions
68
src/test/groovy/be/amedee/adventofcode/aoc2015/day01/Day01Test.groovy
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.