Created
July 10, 2013 04:59
-
-
Save karmiclychee/5963586 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 NumberCruncher | |
def initialize(input) | |
@initial_string = input | |
end | |
def crunch(working=@initial_string) | |
p working = working.to_s | |
sum = working.split('').map(&:to_i).inject(:+) | |
sum <= 9 ? p(sum.to_s) : crunch(sum) | |
end | |
end | |
NumberCruncher.new(ARGV.first).crunch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment