#! /usr/bin/julia

# Rosetta Code, Digital root

function digitalroot{S<:Integer,T<:Integer}(n::S, bs::T=10)
    -1 < n && 1 < bs || throw(DomainError())
    ds = n
    pers = 0
    while bs <= ds
        ds = sum(digits(ds, bs))
        pers += 1
    end
    return (pers, ds)
end
    
for i in {627615, 39390, 588225, 393900588225, big(2)^100}
    (pers, ds) = digitalroot(i)
    println(i, " has persistence ", pers, " and digital root ", ds)
end
        



