Problem 16 » 履歴 » バージョン 2
Noppi, 2023/12/31 00:54
| 1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
|---|---|---|---|
| 2 | # [[Problem 16]] |
||
| 3 | |||
| 4 | ## Power Digit Sum |
||
| 5 | $2^{15} = 32768$ and the sum of its digits is $3 + 2 + 7 + 6 + 8 = 26$. |
||
| 6 | What is the sum of the digits of the number $2^{1000}$? |
||
| 7 | |||
| 8 | ## 各位の数字の和 |
||
| 9 | $2^{15} = 32768$ であり, 各位の数字の和は $3 + 2 + 7 + 6 + 8 = 26$ となる. |
||
| 10 | 同様にして, $2^{1000}$ の各位の数字の和を求めよ. |
||
| 11 | 注: Problem 20 も各位の数字の和に関する問題です。解いていない方は解いてみてください。 |
||
| 12 | |||
| 13 | ```scheme |
||
| 14 | 2 | Noppi | #!r6rs |
| 15 | #!chezscheme |
||
| 16 | |||
| 17 | (import (chezscheme)) |
||
| 18 | |||
| 19 | (define (each-numbers num) |
||
| 20 | (let ([number-chars (string->list (number->string num))]) |
||
| 21 | (map |
||
| 22 | (lambda (char) |
||
| 23 | (char- char #\0)) |
||
| 24 | number-chars))) |
||
| 25 | |||
| 26 | (define answer-16 |
||
| 27 | (apply + (each-numbers (expt 2 1000)))) |
||
| 28 | |||
| 29 | (printf "16: ~D~%" answer-16) |
||
| 30 | 1 | Noppi | ``` |