Skip to content

Instantly share code, notes, and snippets.

@BKDruby
Last active June 8, 2017 20:53
Show Gist options
  • Save BKDruby/71e47d1b4e7e898ec7a7913d22a75fc0 to your computer and use it in GitHub Desktop.
Save BKDruby/71e47d1b4e7e898ec7a7913d22a75fc0 to your computer and use it in GitHub Desktop.
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