Skip to content

Instantly share code, notes, and snippets.

View BertZZ's full-sized avatar

Bertie Wooles BertZZ

View GitHub Profile
@BertZZ
BertZZ / oxygen.rb
Last active December 4, 2021 02:46
Advent of Code Day 3 part 2 find Oxygen method
def find_oxygen(data)
input = data.clone
bits = input[0].length
for i in 0..bits - 1
ones = input.count { |n| n[i] == "1" }
zeros = input.count { |n| n[i] == "0" }
most_common = ones > zeros ? "1" : "0"
most_common = "1" if ones == zeros