-
Notifications
You must be signed in to change notification settings - Fork 1
/
recognizer.scm
61 lines (47 loc) · 1.25 KB
/
recognizer.scm
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
; vim: set expandtab:
(declare (unit recognizer))
(module recognizer
(advance-prime-count
circle-incr
make-prime-counter
recognizer )
(import
(chicken base)
scheme
srfi-1)
(define-syntax advance-prime-count
(syntax-rules ()
((_ lst)
(begin
(set-car! lst 0)
(set! lst (cdr lst))))))
;;; Increment each element of a circular list
(define (circle-incr lst)
(do ((i 0 (+ 1 i)))
((= 4 i))
(set! (list-ref lst i) (add1 (list-ref lst i)))))
(define (make-prime-counter)
(circular-list -100 -100 -100 -100))
(define (recognizer lst)
(let ((lst (take lst 4)))
(cond
((list= eq? lst '(8 6 2 0))
'quadruple)
((or (list= eq? (drop lst 1) '(6 4 0))
(list= eq? (drop lst 1) '(6 2 0)))
'triplet)
((list= eq? (drop lst 2) '(8 0))
'octomus)
((list= eq? (drop lst 2) '(6 0))
'sexy)
((list= eq? (drop lst 2) '(4 0))
'cousin)
((list= eq? (drop lst 2) '(2 0))
'twin)
; 59 is the 17th prime - this also marks a full
; minute without a prime number occurring
((> (list-ref lst 2) 59)
'combo-breaker)
(else
#f))))
); module