Project Euler: Problem 16
すぐ解ける問題から飛ばし飛ばしに解いてしまうのはあまり良くないかな…。
2^(15) = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^(1000)?
http://projecteuler.net/index.php?section=problems&id=16
2 の 1000 乗の各桁の数を合計したものを求めよとのこと。
Gauche で書いてみた。
#!/usr/bin/env gosh (define (main args) (let* [(a 2) (b 1000) (c (expt a b))] (let loop [(num c) (lis '())] (if (<= 10 num) (loop (quotient num 10) (cons (remainder num 10) lis)) (print (fold + 0 (cons num lis)))))) 0)
特に難しいことは考えず、そのまんま。