Problem 1 » 履歴 » バージョン 3
Noppi, 2023/12/27 11:53
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 1]] |
||
3 | |||
4 | 3 | Noppi | ## Multiples of $3$ or $5$ |
5 | If we list all the natural numbers below $10$ that are multiples of $3$ or $5$, we get $3, 5, 6$ and $9$. The sum of these multiples is $23$. |
||
6 | Find the sum of all the multiples of $3$ or $5$ below $1000$. |
||
7 | |||
8 | ## 3と5の倍数 |
||
9 | 10未満の自然数のうち, 3 もしくは 5 の倍数になっているものは 3, 5, 6, 9 の4つがあり, これらの合計は 23 になる. |
||
10 | 同じようにして, 1000 未満の 3 か 5 の倍数になっている数字の合計を求めよ. |
||
11 | |||
12 | 1 | Noppi | ```scheme |
13 | #!r6rs |
||
14 | #!chezscheme |
||
15 | |||
16 | (import (chezscheme)) |
||
17 | |||
18 | (define answer-1 |
||
19 | 3 | Noppi | (fold-left |
20 | (lambda (sum current) |
||
21 | (if (or |
||
22 | (zero? (mod current 3)) |
||
23 | (zero? (mod current 5))) |
||
24 | (+ sum current) |
||
25 | sum)) |
||
26 | 0 |
||
27 | (iota 1000))) |
||
28 | 1 | Noppi | |
29 | (printf "1: ~D~%" answer-1) |
||
30 | ``` |