You are viewing a single comment's thread. Return to all comments →
Excellent optimization problem. Here is my solution in Racket. Passes all tests without any weird tricks for the last two tests.
(define (super-digit n) (if (< n 10) n (super-digit (sum-digits n)))) (define (sum-digits n) (if (zero? n) 0 (begin (let-values ([(x y) (quotient/remainder n 10)]) (+ y (sum-digits x)))))) (define n (read)) (define k (read)) (displayln (super-digit (* k (sum-digits n))))
Seems like cookies are disabled on this browser, please enable them to open this website
Super Digit
You are viewing a single comment's thread. Return to all comments →
Excellent optimization problem. Here is my solution in Racket. Passes all tests without any weird tricks for the last two tests.