-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path035.scm
21 lines (20 loc) · 882 Bytes
/
035.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(add-load-path "." :relative)
(use eulerlib)
; 各桁に偶数と5を含まないような素数のみ確認する
; (2, 5も巡回素数なので後で足しておく)
(define (e35)
(define (rotate l) (append (cdr l) `(,(car l))))
(let ((ps (primes 1000000))
(ht (make-hash-table)))
(dolist (p ps) (hash-table-put! ht p #t))
(+ 2 ; 2, 5
(length (filter
(^p (let1 l (integer->list p)
(and (not (any (^n (or (= 5 n) (even? n))) l))
(let loop ((l (rotate l))
(c (- (length l) 1)))
(cond ((zero? c) #t)
((hash-table-get ht (list->integer l) #f)
(loop (rotate l) (- c 1)))
(else #f))))))
ps)))))