diff --git a/03/main.go b/03/main.go index b551bcc..4e55e21 100644 --- a/03/main.go +++ b/03/main.go @@ -59,26 +59,18 @@ func partOne() { func partTwo() { scanner := makeScanner(false) - var lines int - inputs := map[int]int64{} + inputs := []int64{} var oxgen, co2scrub int64 - var totalOnes, bitlen int64 + var bitlen int64 for scanner.Scan() { line := scanner.Text() n, _ := strconv.ParseInt(line, 2, 64) - inputs[lines] = n - bitlen = int64(len(line)) - 1 - totalOnes += n >> (bitlen) - lines++ - } - // make initial check - if totalOnes >= int64(lines)/2 { - oxgen += (1 << bitlen) - } else { - co2scrub += (1 << bitlen) + inputs = append(inputs, n) + bitlen = int64(len(line)) } + // on initial loop, oxgen>>i == n>>i etc always come out to 0 == 0 for i := bitlen; i > 0; i-- { var oxOnes, oxZeroes, coOnes, coZeroes int64 for _, n := range inputs {