-
Notifications
You must be signed in to change notification settings - Fork 1
/
35.rkt
25 lines (19 loc) · 720 Bytes
/
35.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#lang racket
(require math/number-theory
"digits.ss"
(only-in srfi/1 circular-list every)
rackunit)
(define (all-rotations seq)
(let ([circ (apply circular-list seq)]
[len (length seq)])
(for/list ([l (in-range len)])
(take (list-tail circ l) len))))
(check-equal?
(apply set (all-rotations (list 'a 'b 'c 'd)))
(set '(d a b c) '(c d a b) '(b c d a) '(a b c d)))
(define (all-number-rotations n)
(map digits->number (all-rotations (digits n))))
(define (circular-prime? n)
(every prime? (all-number-rotations n)))
(let ([result (filter circular-prime? (map add1 (build-list 1000000 values)))])
(printf "~a circular primes: ~a~%" (length result) result))