Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
commit 52a6ef48dd
10248 changed files with 63675 additions and 6796 deletions

View file

@ -0,0 +1,18 @@
def digital_root_with_persistence(n : Int) : {Int32, Int32}
n = n.abs
persistence = 0
until n <= 9
persistence += 1
digit_sum = (0..(Math.log10(n).floor.to_i)).sum { |i| (n % 10**(i + 1) - n % 10**i) // 10**i }
n = digit_sum
end
{n, persistence}
end
puts digital_root_with_persistence 627615
puts digital_root_with_persistence 39390
puts digital_root_with_persistence 588225