Problem 1 » 履歴 » バージョン 4
Noppi, 2023/12/28 01:25
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 | 4 | Noppi | (define (3or5-multiple-numbers num) |
19 | (filter |
||
20 | (lambda (n) |
||
21 | (or |
||
22 | (zero? (mod n 3)) |
||
23 | (zero? (mod n 5)))) |
||
24 | (iota num))) |
||
25 | |||
26 | 3 | Noppi | (define answer-1 |
27 | 4 | Noppi | (apply + (3or5-multiple-numbers 1000))) |
28 | 1 | Noppi | |
29 | (printf "1: ~D~%" answer-1) |
||
30 | ``` |