Remove output

This commit is contained in:
Daniel Flanagan 2021-12-03 15:54:00 -06:00
parent 4a3644544b
commit f7204995ff

View file

@ -29,40 +29,29 @@ proc lifeSupportRating(inputs: seq[string]): int =
let width: Natural = inputs[0].len() let width: Natural = inputs[0].len()
var oxygenRating, co2Rating = 0 var oxygenRating, co2Rating = 0
var oxygenCandidates, co2Candidates: seq[int] = toSeq(0..<inputs.len) var oxygenCandidates, co2Candidates: seq[int] = toSeq(0..<inputs.len)
echo oxygenCandidates, co2Candidates
for i in 0..<width: for i in 0..<width:
var newOxygenCandidates, newCo2Candidates: seq[int] = @[] var newOxygenCandidates, newCo2Candidates: seq[int] = @[]
if oxygenRating == 0: if oxygenRating == 0:
let candidates = oxygenCandidates.mapIt(inputs[it]) let candidates = oxygenCandidates.mapIt(inputs[it])
let counters = countBits(candidates, some(1), i) let counters = countBits(candidates, some(1), i)
let moreCommon: char = if counters[0].ones >= counters[0].zeroes: '1' else: '0' let moreCommon: char = if counters[0].ones >= counters[0].zeroes: '1' else: '0'
echo "OX: ", i, candidates, moreCommon, counters[0]
if counters[0].zeroes == counters[0].ones:
echo "SAME OX"
for j in oxygenCandidates: for j in oxygenCandidates:
if inputs[j][i] == moreCommon: if inputs[j][i] == moreCommon:
newOxygenCandidates.add(j) newOxygenCandidates.add(j)
if newOxygenCandidates.len() == 1: if newOxygenCandidates.len() == 1:
discard inputs[newOxygenCandidates[0]].parseBin(oxygenRating) discard inputs[newOxygenCandidates[0]].parseBin(oxygenRating)
echo "OX DONE"
if co2Rating == 0: if co2Rating == 0:
let candidates = co2Candidates.mapIt(inputs[it]) let candidates = co2Candidates.mapIt(inputs[it])
let counters = countBits(candidates, some(1), i) let counters = countBits(candidates, some(1), i)
let lessCommon: char = if counters[0].zeroes <= counters[0].ones: '0' else: '1' let lessCommon: char = if counters[0].zeroes <= counters[0].ones: '0' else: '1'
echo "CO2 ", i, candidates, lessCommon, counters[0]
if counters[0].zeroes == counters[0].ones:
echo "SAME CO2"
for j in co2Candidates: for j in co2Candidates:
if inputs[j][i] == lessCommon: if inputs[j][i] == lessCommon:
newCo2Candidates.add(j) newCo2Candidates.add(j)
if newCo2Candidates.len() == 1: if newCo2Candidates.len() == 1:
discard inputs[newCo2Candidates[0]].parseBin(co2Rating) discard inputs[newCo2Candidates[0]].parseBin(co2Rating)
echo "CO2 DONE"
oxygenCandidates = newOxygenCandidates oxygenCandidates = newOxygenCandidates
co2Candidates = newCo2Candidates co2Candidates = newCo2Candidates
if oxygenRating != 0 and co2Rating != 0: break if oxygenRating != 0 and co2Rating != 0: break
echo "OX: ", oxygenRating
echo "CO2: ", co2Rating
return oxygenRating * co2Rating return oxygenRating * co2Rating
let input = 3.loadInput() let input = 3.loadInput()