Code for the Advent of Code event
aoc
advent-of-code
1#!/usr/bin/env ruby
2# frozen_string_literal: true
3
4counts = []
5
6$stdin.readlines.map(&:strip).tap do |input|
7 input.first.size.times { counts << Hash.new(0) }
8end.each do |message|
9 message.chars.each.with_index { |c, i| counts[i][c] += 1 }
10end
11
12sorted = counts.map { |p| p.keys.sort { |a, b| p[b] <=> p[a] } }
13
14puts "(1) #{sorted.map(&:first).join}"
15puts "(2) #{sorted.map(&:last).join}"