object day03 { def main(args: Array[String]): Unit = { val numbers = io.Source.stdin .getLines() .map(ln => ln.chars.map(_ - '0').toArray) .toArray var occurences = Array.fill(numbers(0).length)(0) for (number <- numbers) { for ((bit, i) <- number.zipWithIndex) occurences(i) += bit } var gamma = 0 var epsilon = 0 for ((freq, i) <- occurences.zipWithIndex) { val shifted = 1 << occurences.length - 1 >> i if (freq > (numbers.length / 2)) gamma |= shifted else epsilon |= shifted } val part1 = gamma * epsilon println(s"part1: $part1") } }