remove special-case initial loop nonsense
This commit is contained in:
parent
b6f7a57580
commit
f6abc0c6e1
18
03/main.go
18
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user