Ad

Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.

999 --> 4 (because 999 = 729, 729 = 126, 126 = 12, and finally 1*2 = 2)
4 --> 0 (because 4 is already a one-digit number)

def persistence(n)
    return 0 if n < 10

    mult = n.digits.reduce(:*)
    count = 1

  until mult < 10 do
    mult = mult.digits.reduce(:*)
    count += 1
  end

  count
end