-
Notifications
You must be signed in to change notification settings - Fork 0
/
probs.yml
executable file
·283 lines (270 loc) · 5.46 KB
/
probs.yml
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
- name: Hello World
difficulty: 0
parts:
- |
package main
import "fmt"
// Returns "Hello World", as is customary in first examples
func solve() string {
return ""
}
tests:
- input:
output:
- '"Hello World"'
- name: Simple math
difficulty: 1
parts:
- |
package main
import "fmt"
// Returns the sum of all of all three parameters
func solve(a, b, c int) int {
return 0
}
tests:
- input:
- 1, 2, 7
output:
- 10
- input:
- 4, 5, 6
output:
- 15
- name: Ifs
difficulty: 1
help: &ifhelp http://golangtutorials.blogspot.com/2011/06/control-structures-if-else-statement.html
hint: |
Here is an example of how to return the value 7 when a is equal to 3:
if a == 3 {
return 7
}
Notice the fact that you must say "==" rather than just "=".
parts:
- |
package main
import "fmt"
// If a is 0, return the sum of b and c
// If a is 1, return the product of b and c
// Otherwise, return -1
func solve(a, b, c int) int {
return 0
}
tests:
- input:
- 0, 1, 5
output:
- 6
- input:
- 0, 5, -9
output:
- -4
- input:
- 1, 5, 5
output:
- 25
- input:
- 1, 9, 10
output:
- 90
- input:
- -1, 5, 6
output:
- -1
- input:
- 42, 77, 10
output:
- -1
- name: Booleans 1
difficulty: 1
help: &boolhelp 'http://golang.org/ref/spec#Logical_operators'
hint: &boolhint |
Consider the following input-output relationships for these "boolean operations":
AND (conjunction):
`true && true` turns into `true`
`true && false` turns into `false`
`false && false` turns into `false`
`false && false` turns into `false`
OR (disjunction):
`true || true` turns into `true`
`true || false` turns into `true`
`false || false` turns into `true`
`false || false` turns into `false`
NOT (negation, opposite):
`!true` turns into `false`
`!false` turns into `true`
parts:
- |
package main
import "fmt"
// Return true if both a and b are true. Otherwise return false.
func solve(a, b bool) bool {
return false
}
tests:
- input:
- true, true
output:
- true
- input:
- true, false
output:
- false
- input:
- false, true
output:
- false
- input:
- false, false
output:
- false
- name: Booleans 2
difficulty: 1
help: *boolhelp
hint: *boolhint
parts:
- |
package main
import "fmt"
// When a is true return the opposite of b. When a is false return true.
func solve(a, b bool) bool {
return false
}
tests:
- input:
- true, true
output:
- false
- input:
- true, false
output:
- true
- input:
- false, true
output:
- true
- input:
- false, false
output:
- true
- name: Booleans 3
difficulty: 2
help: *boolhelp
hint: *boolhint
parts:
- |
package main
import "fmt"
// Return true if exactly one out of a, b, and c is true. Else return false.
func solve(a, b, c bool) bool {
return false
}
tests:
- input:
- false, false, false
output:
- false
- input:
- false, false, true
output:
- true
- input:
- false, true, false
output:
- true
- input:
- false, true, true
output:
- false
- input:
- true, false, false
output:
- true
- input:
- true, false, true
output:
- false
- input:
- true, true, false
output:
- false
- input:
- true, true, true
output:
- false
- name: Average math
difficulty: 2
help: 'http://golang.org/ref/spec#Operator_precedence'
hint: Remember to use parenthesis to ensure order of operation!
parts:
- |
package main
import "fmt"
// Returns the average of all three parameters
func solve(a, b, c int) int {
return 0
}
tests:
- input:
- 1, 2, 6
output:
- 3
- input:
- 4, 5, 6
output:
- 5
- name: Max
difficulty: 2
help: *ifhelp
hint: If a is greater than b, return a. Else return b.
parts:
- |
package main
import "fmt"
// Returns the larger of the two parameters 'a' and 'b'. In the
// event of a tie return that number.
func solve(a, b int) int {
return 0
}
tests:
- input:
- 1, 2
output:
- 2
- input:
- 8, 6
output:
- 8
- input:
- 1, 1
output:
- 1
- name: Slices 1
difficulty: 2
help: &slicehelp 'http://golang.org/doc/effective_go.html#slices'
parts:
- |
package main
import "fmt"
// Return the sum of the 0th element and the last element of the slice
// You may assume that the slice has at least a single element.
func solve(a []int) int {
return 0
}
tests:
- input:
- '[]int{1, 2}'
output:
- 3
- input:
- '[]int{1, 4, 5, 6, 7, 8, 9, 0, 1, 4, 8}'
output:
- 9
- input:
- '[]int{1, 2, 7, 9, -3}'
output:
- -2
- input:
- '[]int{1}'
output:
- 2