-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo1-solution.clj
147 lines (121 loc) · 2.6 KB
/
video1-solution.clj
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(defn add-egg []
(grab :egg)
(squeeze)
(add-to-bowl))
(defn add-sugar []
(grab :cup)
(scoop :sugar)
(add-to-bowl)
(release))
(defn add-flour []
(grab :cup)
(scoop :flour)
(add-to-bowl)
(release))
(defn add-milk []
(grab :cup)
(scoop :milk)
(add-to-bowl)
(release))
(defn add-butter []
(grab :butter)
(add-to-bowl))
(defn scooped? [ingredient]
(cond
(= ingredient :milk)
true
(= ingredient :flour)
true
(= ingredient :sugar)
true
:else
false))
(defn squeezed? [ingredient]
(= ingredient :egg))
(defn simple? [ingredient]
(= ingredient :butter))
(defn add-eggs [n]
(dotimes [e n]
(add-egg)))
(defn add-flour-cups [n]
(dotimes [e n]
(add-flour)))
(defn add-milk-cups [n]
(dotimes [e n]
(add-milk)))
(defn add-sugar-cups [n]
(dotimes [e n]
(add-sugar)))
(defn add-butters [n]
(dotimes [e n]
(add-butter)))
(defn add-squeezed
([ingredient]
(add-squeezed ingredient 1))
([ingredient amount]
(if (squeezed? ingredient)
(dotimes [i amount]
(grab ingredient)
(squeeze)
(add-to-bowl))
(do
(println "This function only works on squeezed ingredients. You asked me to squeeze" ingredient)
:error))))
(defn add-scooped
([ingredient]
(add-scooped ingredient 1))
([ingredient amount]
(if (scooped? ingredient)
(do
(grab :cup)
(dotimes [i amount]
(scoop ingredient)
(add-to-bowl))
(release))
(do
(println "This function only works on scooped ingredients. You asked me to scoop" ingredient)
:error))))
(defn add-simple
([ingredient]
(add-simple ingredient 1))
([ingredient amount]
(if (simple? ingredient)
(dotimes [i amount]
(grab ingredient)
(add-to-bowl))
(do
(println "This function only works on simple ingredients. You asked me to add" ingredient)
:error))))
(defn add
([ingredient]
(add ingredient 1))
([ingredient amount]
(cond
(squeezed? ingredient)
(add-squeezed ingredient amount)
(simple? ingredient)
(add-simple ingredient amount)
(scooped? ingredient)
(add-scooped ingredient amount)
:else
(do
(println "I do not have the ingredient" ingredient)
:error))))
(defn bake-cake []
(add :egg 2)
(add :flour 2)
(add :milk 1)
(add :sugar 1)
(mix)
(pour-into-pan)
(bake-pan 25)
(cool-pan))
(defn bake-cookies []
(add :egg 1)
(add :flour 1)
(add :butter 1)
(add :sugar 1)
(mix)
(pour-into-pan)
(bake-pan 30)
(cool-pan))