-
Notifications
You must be signed in to change notification settings - Fork 1
/
78.ss
41 lines (35 loc) · 929 Bytes
/
78.ss
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
; Project Euler
; Problem 78
; Number of ways that coins can be separated into piles
(define (cc amount coin-values)
(cond ((= amount 0) 1)
((or (< amount 0) (no-more? coin-values)) 0)
(else
(+ (cc amount
(except-first-denomination coin-values))
(cc (- amount
(first-denomination coin-values))
coin-values)))))
(define (first-denomination coins)
(car coins))
(define (except-first-denomination coins)
(cdr coins))
(define (no-more? coins)
(null? coins))
(define (range-list n)
(if (= n 0)
'()
(append (list n)
(range-list (- n 1)))))
(define (combo n)
(cc n (range-list n)))
(define (euler-78)
(define (try-n n)
(cond ((= 0 (remainder n 10))
(display n)
(newline)))
(if (= 0 (remainder (combo n) 1000000))
n
(try-n (+ n 1))))
(try-n 1))
(euler-78)