プロジェクト

全般

プロフィール

Problem 7 » 履歴 » バージョン 1

Noppi, 2023/12/27 01:42

1 1 Noppi
[ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]]
2
# [[Problem 7]]
3
4
```scheme
5
#!r6rs
6
#!chezscheme
7
8
(import (chezscheme))
9
10
(define (prime? num)
11
  (if (even? num)
12
    #f
13
    (let ((count (isqrt num)))
14
      (let loop ((check-num 3))
15
        (cond
16
          [(< count check-num) #t]
17
          [(zero? (mod num check-num)) #f]
18
          [else (loop (+ check-num 2))])))))
19
20
(define answer-7
21
  (let loop ((current 3) (count 1) (prime 2))
22
    (if
23
      (= 10001 count)
24
      prime
25
      (let ((next (+ current 2)))
26
        (if (prime? current)
27
          (loop next (add1 count) current)
28
          (loop next count prime))))))
29
30
(printf "7: ~D~%" answer-7)
31
```