day(03): refactor
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
91aa2e41b7
commit
47f865d9aa
1 changed files with 41 additions and 49 deletions
|
@ -2,12 +2,9 @@ package day03
|
|||
|
||||
import readInput
|
||||
|
||||
fun main() {
|
||||
fun toBits(input: List<String>): List<List<Int>> {
|
||||
return input.map { row ->
|
||||
fun toBits(input: List<String>): List<List<Int>> = input.map { row ->
|
||||
row.map { if (it == '1') 1 else 0 }
|
||||
}
|
||||
}
|
||||
|
||||
fun part1(input: List<List<Int>>): Int {
|
||||
var gamma = 0
|
||||
|
@ -17,13 +14,8 @@ fun main() {
|
|||
gamma = gamma.shl(1)
|
||||
epsilon = epsilon.shl(1)
|
||||
|
||||
val ones = input.indices.map { input[it][i] }.sum()
|
||||
|
||||
if (2 * ones > input.size) {
|
||||
gamma++
|
||||
} else {
|
||||
epsilon++
|
||||
}
|
||||
val ones = input.indices.sumOf { input[it][i] }
|
||||
if (2 * ones > input.size) gamma++ else epsilon++
|
||||
}
|
||||
|
||||
return epsilon * gamma
|
||||
|
@ -51,7 +43,7 @@ fun main() {
|
|||
return oxygenGeneratorRating * co2ScrubberRating
|
||||
}
|
||||
|
||||
|
||||
fun main() {
|
||||
val testInput = toBits(readInput(3, "test_input"))
|
||||
val input = toBits(readInput(3, "input"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue