Skip to content

Instantly share code, notes, and snippets.

@danielmciotti
Created January 14, 2022 02:13
Show Gist options
  • Save danielmciotti/fe91105a3a64370fd21a57d7e115af36 to your computer and use it in GitHub Desktop.
Save danielmciotti/fe91105a3a64370fd21a57d7e115af36 to your computer and use it in GitHub Desktop.
def split(input)
remainders = []
loop do
quotient, remainder = input.divmod(10)
remainders << remainder
break if quocient.zero?
input = quotient
end
remainders
end
def sum_of_splits(input)
total = input
loop do
total = split(total).sum
break if total < 10
end
total
end
# Second attempt
def sum_2(input)
aux = input
loop do
aux = aux.to_s.chars.map(&:to_i).sum
break if aux < 10
end
aux
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment