1
0
mirror of https://github.com/chylex/Advent-of-Code.git synced 2025-06-01 03:34:05 +02:00

Add 2021 - Day 2 - Part 1

This commit is contained in:
chylex 2021-12-02 10:36:06 +01:00
parent 896b802e7f
commit 457d8ef8a8
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
4 changed files with 1033 additions and 0 deletions
.idea/runConfigurations
2021/02
build.gradle.kts

View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2021 - Day 02" type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME" value="MainKt" />
<module name="Advent_of_Code.2021-02" />
<shortenClasspath name="NONE" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/2021/02" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

1000
2021/02/input/1.txt Normal file

File diff suppressed because it is too large Load Diff

21
2021/02/main.kt Normal file
View File

@ -0,0 +1,21 @@
import java.io.File
fun main() {
val lines = File("input/1.txt").readLines()
val directions = lines.map { line -> line.split(' ', limit = 2).let { it[0] to it[1].toInt() } }
var position = 0
var depth = 0
for ((direction, distance) in directions) {
when (direction) {
"forward" -> position += distance
"up" -> depth -= distance
"down" -> depth += distance
}
}
println("Position: $position")
println("Depth: $depth")
println("Multiplied: ${position * depth}")
}

View File

@ -33,4 +33,5 @@ sourceSets {
}
make(2021, 1)
make(2021, 2)
}