Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mostFrequentDigitSum(n)
- amount = Array.new
- x = 0
- y = 0
- number = n
- sum = 0
- string = n.to_s
- while (number > 0)
- while (x < string.length)
- sum = sum + string[x].to_i
- x = x + 1
- end
- amount[y] = sum
- y = y + 1
- number = number - sum
- sum = 0
- x = 0
- string = number.to_s
- end
- amount = amount.sort
- amount = amount.reverse
- return amount.max_by {|i| amount.count(i)}
- end
Advertisement
Add Comment
Please, Sign In to add comment