プロジェクト

全般

プロフィール

Problem 9 » 履歴 » バージョン 2

Noppi, 2023/12/27 04:53

1 1 Noppi
[ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]]
2
# [[Problem 9]]
3
4
```scheme
5
#!r6rs
6
#!chezscheme
7
8
(import (chezscheme))
9
10
(define answer-9
11 2 Noppi
  (let loop1 ([a 1])
12 1 Noppi
    (if (< 333 a)
13
      (error "answer-9" "answer-9 was not found!")
14 2 Noppi
      (let loop2 ([b a])
15 1 Noppi
        (if (< 499 b)
16
          (loop1 (add1 a))
17 2 Noppi
          (let ([c (- 1000 a b)])
18
            (if (= (+ (expt a 2)
19
                      (expt b 2))
20
                   (expt c 2))
21 1 Noppi
              (* a b c)
22
              (loop2 (add1 b)))))))))
23
24
(printf "9: ~D~%" answer-9)
25
```