-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path27.ss
More file actions
executable file
·32 lines (25 loc) · 727 Bytes
/
27.ss
File metadata and controls
executable file
·32 lines (25 loc) · 727 Bytes
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
26
27
28
29
30
31
32
#lang scheme
(require math/number-theory)
(define (prime/safe n)
(and (positive? n)
(prime? n)))
(define (number-of-consecutive-primes quadratic)
(let loop ((n 0))
(if (prime/safe (quadratic n))
(loop (add1 n))
n)))
(module+ main
(define-values (best length)
(for*/fold ([best-quadratic #f]
[length 0])
([a (in-range -1000 1000)]
[b (in-range -1000 1000)])
(define (quadratic n)
(+ (* n n)
(* n a)
b))
(let ((this-length (number-of-consecutive-primes quadratic)))
(if (< length this-length)
(values (list a b) this-length)
(values best-quadratic length)))))
(apply * best))