Skip to content

Instantly share code, notes, and snippets.

@wconrad
Created December 10, 2015 11:50
Show Gist options
  • Save wconrad/9900288ad4954faa8691 to your computer and use it in GitHub Desktop.
Save wconrad/9900288ad4954faa8691 to your computer and use it in GitHub Desktop.
Advent of Code, day 10
#!/usr/bin/env ruby
# http://adventofcode.com/day/10
INPUT = "1113222113"
def look_and_say(s)
s.gsub(/(.)\1*/) do
"#{$&.size}#{$1}"
end
end
def look_and_say_repeatedly(s, count)
count.times do
s = look_and_say(s)
end
s
end
[40, 50].each do |count|
puts look_and_say_repeatedly(INPUT, count).length
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment