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() {
|
func partTwo() {
|
||||||
scanner := makeScanner(false)
|
scanner := makeScanner(false)
|
||||||
|
|
||||||
var lines int
|
inputs := []int64{}
|
||||||
inputs := map[int]int64{}
|
|
||||||
var oxgen, co2scrub int64
|
var oxgen, co2scrub int64
|
||||||
|
|
||||||
var totalOnes, bitlen int64
|
var bitlen int64
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
n, _ := strconv.ParseInt(line, 2, 64)
|
n, _ := strconv.ParseInt(line, 2, 64)
|
||||||
inputs[lines] = n
|
inputs = append(inputs, n)
|
||||||
bitlen = int64(len(line)) - 1
|
bitlen = int64(len(line))
|
||||||
totalOnes += n >> (bitlen)
|
|
||||||
lines++
|
|
||||||
}
|
|
||||||
// make initial check
|
|
||||||
if totalOnes >= int64(lines)/2 {
|
|
||||||
oxgen += (1 << bitlen)
|
|
||||||
} else {
|
|
||||||
co2scrub += (1 << bitlen)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on initial loop, oxgen>>i == n>>i etc always come out to 0 == 0
|
||||||
for i := bitlen; i > 0; i-- {
|
for i := bitlen; i > 0; i-- {
|
||||||
var oxOnes, oxZeroes, coOnes, coZeroes int64
|
var oxOnes, oxZeroes, coOnes, coZeroes int64
|
||||||
for _, n := range inputs {
|
for _, n := range inputs {
|
||||||
|
Loading…
Reference in New Issue
Block a user