Solved part 1
parent
19a0563550
commit
e36d97951a
File diff suppressed because it is too large
Load Diff
|
@ -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}"
|
||||||
|
|
Loading…
Reference in New Issue