day(02): refactor
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
e3e721b6b4
commit
91aa2e41b7
1 changed files with 43 additions and 46 deletions
|
@ -6,7 +6,6 @@ enum class Command {
|
||||||
FORWARD, DOWN, UP
|
FORWARD, DOWN, UP
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
|
||||||
data class Position(val horizontal: Int = 0, val depth: Int = 0, val aim: Int = 0)
|
data class Position(val horizontal: Int = 0, val depth: Int = 0, val aim: Int = 0)
|
||||||
data class Instruction(val type: Command, val value: Int)
|
data class Instruction(val type: Command, val value: Int)
|
||||||
|
|
||||||
|
@ -23,9 +22,7 @@ fun main() {
|
||||||
throw IllegalArgumentException("Cannot parse instruction")
|
throw IllegalArgumentException("Cannot parse instruction")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toCommands(input: List<String>): List<Instruction> {
|
fun toCommands(input: List<String>): List<Instruction> = input.map { parseInstruction(it) }
|
||||||
return input.map { parseInstruction(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun part1(input: List<Instruction>): Int {
|
fun part1(input: List<Instruction>): Int {
|
||||||
val finalPosition = input.fold(Position()) { pos, instruction ->
|
val finalPosition = input.fold(Position()) { pos, instruction ->
|
||||||
|
@ -52,7 +49,7 @@ fun main() {
|
||||||
return finalPosition.horizontal * finalPosition.depth
|
return finalPosition.horizontal * finalPosition.depth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
val testInput = toCommands(readInput(2, "test_input"))
|
val testInput = toCommands(readInput(2, "test_input"))
|
||||||
val input = toCommands(readInput(2, "input"))
|
val input = toCommands(readInput(2, "input"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue