Last active
June 8, 2017 20:53
-
-
Save BKDruby/71e47d1b4e7e898ec7a7913d22a75fc0 to your computer and use it in GitHub Desktop.
This file contains 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
class Integer | |
def look_and_say | |
num = self | |
Enumerator.new do |y| | |
loop do | |
y << num | |
num = get_next_saynum(num) | |
end | |
end | |
end | |
private | |
def get_next_saynum(num) | |
num.to_s.gsub(/(.)\1*/) { |s| s.size.to_s + s[0] }.to_i | |
end | |
end | |
p 10.look_and_say.each.take(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment