Only took a few minutes today; here is what I got in Ruby:
require 'benchmark' class GroupAnswers def self.from_lines(lines) GroupAnswers.new(lines.map(&:chomp)) end def initialize(people) questions = people.join('').chars.uniq self.count = questions.count { |q| people.all? { |l| l.include?(q) } } end def to_i self.count end private attr_accessor :count end groups = File .read('input.txt') .split(/\n\n/) Benchmark.bmbm do |b| b.report do puts groups.sum { |group| GroupAnswers.from_lines(group.split(/\n/)).to_i } end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Only took a few minutes today; here is what I got in Ruby: