Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,26 @@
class DigitalRoot {
static int[] calcDigitalRoot(String number, int base) {
BigInteger bi = new BigInteger(number, base)
int additivePersistence = 0
if (bi.signum() < 0) {
bi = bi.negate()
}
BigInteger biBase = BigInteger.valueOf(base)
while (bi >= biBase) {
number = bi.toString(base)
bi = BigInteger.ZERO
for (int i = 0; i < number.length(); i++) {
bi = bi.add(new BigInteger(number.substring(i, i + 1), base))
}
additivePersistence++
}
return [additivePersistence, bi.intValue()]
}
static void main(String[] args) {
for (String arg : [627615, 39390, 588225, 393900588225]) {
int[] results = calcDigitalRoot(arg, 10)
println("$arg has additive persistence ${results[0]} and digital root of ${results[1]}")
}
}
}