Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
12
Task/Digital-root/Scala/digital-root.scala
Normal file
12
Task/Digital-root/Scala/digital-root.scala
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def digitalRoot(x:BigInt, base:Int=10):(Int,Int) = {
|
||||
def sumDigits(x:BigInt):Int=x.toString(base) map (_.asDigit) sum
|
||||
def loop(s:Int, c:Int):(Int,Int)=if (s < 10) (s, c) else loop(sumDigits(s), c+1)
|
||||
loop(sumDigits(x), 1)
|
||||
}
|
||||
|
||||
Seq[BigInt](627615, 39390, 588225, BigInt("393900588225")) foreach {x =>
|
||||
var (s, c)=digitalRoot(x)
|
||||
println("%d has additive persistance %d and digital root of %d".format(x,c,s))
|
||||
}
|
||||
var (s, c)=digitalRoot(0x7e0, 16)
|
||||
println("%x has additive persistance %d and digital root of %d".format(0x7e0,c,s))
|
||||
Loading…
Add table
Add a link
Reference in a new issue