Skip to content

Instantly share code, notes, and snippets.

@qwzybug
Created April 7, 2009 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwzybug/91365 to your computer and use it in GitHub Desktop.
Save qwzybug/91365 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Solve a Joel problem
def chain k
s, c, l = k, 0, [] # start, carry, digit list
begin
l.unshift k
d = 2 * k + c
c, k = d / 10, d % 10
end until k == s and c == 0
l
end
(1..9).each {|k| puts chain(k).join}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment