Code: Select all
Example: n = 7865 = 7 + 8 + 6 + 5 = 26 ==> 2 + 6 = 8
Code: Select all
(define (digitSum n)
(if (zero? n) 0
(if (zero? (% n 9)) 9
(% n 9))))
(digitSum 236753647864)
;-> 7
Code: Select all
Example: n = 7865 = 7 + 8 + 6 + 5 = 26 ==> 2 + 6 = 8
Code: Select all
(define (digitSum n)
(if (zero? n) 0
(if (zero? (% n 9)) 9
(% n 9))))
(digitSum 236753647864)
;-> 7
Code: Select all
(define (digital_root n)
(+ 1 (% (- n 1) 9))
> (digital_root 236753647864)
7