Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Digital-root/OCaml/digital-root.ocaml
Normal file
16
Task/Digital-root/OCaml/digital-root.ocaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
let rec digit_sum b n =
|
||||
if n < b then n else digit_sum b (n / b) + n mod b
|
||||
|
||||
let digital_root b n =
|
||||
let rec loop a x =
|
||||
if x < b then a, x else loop (succ a) (digit_sum b x)
|
||||
in
|
||||
loop 0 n
|
||||
|
||||
let () =
|
||||
let pr_fmt n (p, r) =
|
||||
Printf.printf "%u: additive persistence = %u, digital root = %u\n" n p r
|
||||
in
|
||||
List.iter
|
||||
(fun n -> pr_fmt n (digital_root 10 n))
|
||||
[627615; 39390; 588225; 393900588225]
|
||||
Loading…
Add table
Add a link
Reference in a new issue