Problem 2 » 履歴 » バージョン 1
Noppi, 2023/12/27 01:31
| 1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
|---|---|---|---|
| 2 | # [[Problem 2]] |
||
| 3 | |||
| 4 | ```scheme |
||
| 5 | #!r6rs |
||
| 6 | #!chezscheme |
||
| 7 | |||
| 8 | (import (chezscheme)) |
||
| 9 | |||
| 10 | (define answer-2 |
||
| 11 | (let loop ((first 0) (second 1) (result 0)) |
||
| 12 | (let ((next (+ first second))) |
||
| 13 | (cond |
||
| 14 | [(< 4000000 next) result] |
||
| 15 | [(even? next) |
||
| 16 | (loop second next (+ result next))] |
||
| 17 | [else (loop second next result)])))) |
||
| 18 | |||
| 19 | (printf "2: ~D~%" answer-2) |
||
| 20 | ``` |