Created
December 10, 2015 11:50
-
-
Save wconrad/9900288ad4954faa8691 to your computer and use it in GitHub Desktop.
Advent of Code, day 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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