Solved part 1

master
s00ner 2021-12-03 10:29:07 -05:00
parent 19a0563550
commit e36d97951a
2 changed files with 1020 additions and 0 deletions

1000
day03/input Normal file

File diff suppressed because it is too large Load Diff

20
day03/solution.rb Normal file
View File

@ -0,0 +1,20 @@
#!/bin/env ruby
#part 1
report = File.readlines('./input').map(&:strip)
masks = []
report[0].length.times{ masks.push(2 ** _1) }
report.map!{ _1.to_i(2) }
gamma = 0
masks.each do |mask|
if report.map{ mask & _1 }.reject(&:zero?).count > report.count / 2
gamma += mask
end
end
epsilon = gamma ^ masks.sum
puts "Gamma is #{gamma}"
puts "Epsilon is #{epsilon}"
puts "Power is #{gamma * epsilon}"