advent-of-code/2015/day-10/common.rb
Patrick Auernig 3c57921438 Refactor 2015 days 01 to 10
Split parts into separate files and remove some unused files
2021-12-08 01:05:17 +01:00

23 lines
363 B
Ruby

# frozen_string_literal: true
require "stringio"
def look_and_say(input)
counter = 1
output = input.each_char.map(&:to_i).chain([nil]).each_cons(2).reduce(StringIO.new) do |acc, (val1, val2)|
if val1 == val2
counter += 1
else
acc.write counter
acc.write val1
counter = 1
end
acc
end
output.rewind
output
end