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:
parent
896b802e7f
commit
457d8ef8a8
11
.idea/runConfigurations/2021___Day_02.xml
Normal file
11
.idea/runConfigurations/2021___Day_02.xml
Normal 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
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
21
2021/02/main.kt
Normal 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}")
|
||||
}
|
@ -33,4 +33,5 @@ sourceSets {
|
||||
}
|
||||
|
||||
make(2021, 1)
|
||||
make(2021, 2)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user