Skip to content

Instantly share code, notes, and snippets.

@maxjacobson
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save maxjacobson/2f0680b29eb18c4d9a65 to your computer and use it in GitHub Desktop.

Select an option

Save maxjacobson/2f0680b29eb18c4d9a65 to your computer and use it in GitHub Desktop.
class Lychrel
def initialize(starting_at:)
@start = starting_at
end
def for(iterations:)
last = start
yield last
iterations.times do
last = last + last.to_s.reverse.to_i
yield last
end
end
private
attr_reader :start
end
Lychrel.new(starting_at: 196).for(iterations: ARGV.first.to_i) do |num|
puts num
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment