Yanother Ruby solution
FRUIT = { '1' => 'kiwi', # ... '100' => 'pineapple' } def subtract_sum(number) return unless (10...10_000).cover?(number) loop do number_split = number.to_s.split('') to_subtract = number_split.reduce(0) { |sum, i| sum += i.to_i } number -= to_subtract return FRUIT[number.to_s] if FRUIT.key?(number.to_s) end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yanother Ruby solution