-
Notifications
You must be signed in to change notification settings - Fork 1
/
initial-sketch.rkt
executable file
·99 lines (90 loc) · 2.11 KB
/
initial-sketch.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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(define f
(lambda (x)
(cond
[(= x 0) 1]
[else (* (f (- x 1)) x)])))
(define m
(lambda (i type)
(length (filter (lambda (x) (= i x)) type))))
(define n
(lambda (type)
(cond
[(equal? '() type) 0]
[else (+ (car type) (n (cdr type)))])))
(define build-list
(lambda (m g)
(cond
[(= 0 m) '()]
[else (cons (g m) (build-list (- m 1) g))])))
(define total
(lambda (type)
(/ (f (n type))
(apply * (map (lambda (i)
(* (expt i (m i type))
(f (m i type))))
(build-list (n type)
identity))))))
(define bad
(lambda (type)
(/ (* (f (- (n type) 2))
(apply + (map (lambda (i)
(* (m i type) i (- i 1)))
(build-list (n type)
identity))))
(apply * (map (lambda (i)
(* (expt i (m i type))
(f (m i type))))
(build-list (n type)
identity))))))
(define good
(lambda (type)
(- (total type)
(bad type))))
(define thelist
'((12)
(10 1 1)
(9 2 1)
(8 3 1)
(8 2 2)
(8 1 1 1 1)
(7 4 1)
(7 3 2)
(7 2 1 1 1)
(6 5 1)
(6 4 2)
(6 3 3)
(6 3 1 1 1)
(6 2 2 1 1)
(6 1 1 1 1 1 1)
(5 5 2)
(5 4 3)
(5 4 1 1 1)
(5 3 2 1 1)
(5 2 2 2 1)
(5 2 1 1 1 1 1)
(4 4 4)
(4 4 2 1 1)
(4 3 3 1 1)
(4 3 2 2 1)
(4 3 1 1 1 1 1)
(4 2 2 2 2)
(4 2 2 1 1 1 1)
(4 1 1 1 1 1 1 1 1)
(3 3 3 2 1)
(3 3 2 2 2)
(3 3 2 1 1 1 1)
(3 2 2 2 1 1 1)
(3 2 1 1 1 1 1 1 1)
(2 2 2 2 2 1 1)
(2 2 2 1 1 1 1 1 1)
(2 1 1 1 1 1 1 1 1 1 1)))
;;careful
(define theanswer
(- (* (apply + (map good thelist))
(expt 2 11))
(/ (* (f 11) (expt 2 10)) 2)))
;(/ (f 12) 2)
;(apply + (map total thelist))
;(* (expt 2 11) (apply + (map total thelist)))
;theanswer
(/ theanswer (* (expt 3 7) (apply + (map total thelist))))