#!/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}"