プロジェクト

全般

プロフィール

Problem 7 » 履歴 » リビジョン 2

リビジョン 1 (Noppi, 2023/12/27 01:42) → リビジョン 2/5 (Noppi, 2023/12/27 04:49)

[ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] 
 # [[Problem 7]] 

 ```scheme 
 #!r6rs 
 #!chezscheme 

 (import (chezscheme)) 

 (define (prime? num) 
   (if (even? num) 
     #f 
     (let ([count ((count (isqrt num)]) num))) 
       (let loop ([check-num 3]) ((check-num 3)) 
         (cond 
           [(< count check-num) #t] 
           [(zero? (mod num check-num)) #f] 
           [else (loop (+ check-num 2))]))))) 

 (define answer-7 
   (let loop ([current 3] [count 1] [prime 2]) ((current 3) (count 1) (prime 2)) 
     (if 
       (= 10001 count) 
       prime 
       (let ([next ((next (+ current 2)]) 2))) 
         (if (prime? current) 
           (loop next (add1 count) current) 
           (loop next count prime)))))) 

 (printf "7: ~D~%" answer-7) 
 ```