-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo.toml
471 lines (420 loc) · 8.12 KB
/
info.toml
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# INTRO
[[exercises]]
name = "intro1"
path = "exercises/intro/intro1.nr"
mode = "test"
hint = """
No hints this time ;)
"""
# MERKLE TREE
# [[exercises]]
# name = "merkle-tree"
# path = "exercises/merkle-tree/merkle.nr"
# mode = "test"
# hint = """
# No hints this time ;)
# """
# VARIABLES
[[exercises]]
name = "variables1"
path = "exercises/variables/variables1.nr"
mode = "compile"
hint = """
No hint this time
"""
[[exercises]]
name = "variables2"
path = "exercises/variables/variables2.nr"
mode = "compile"
hint = """
No hint this time
"""
[[exercises]]
name = "variables3"
path = "exercises/variables/variables3.nr"
mode = "compile"
hint = """
No hint this time
"""
[[exercises]]
name = "variables4"
path = "exercises/variables/variables4.nr"
mode = "compile"
hint = """
No hint this time
"""
[[exercises]]
name = "variables5"
path = "exercises/variables/variables5.nr"
mode = "compile"
hint = """
No hint this time
"""
[[exercises]]
name = "variables6"
path = "exercises/variables/variables6.nr"
mode = "compile"
hint = """
No hint this time
"""
# CONTROL FLOW
[[exercises]]
name = "if1"
path = "exercises/control-flow/if1.nr"
mode = "test"
hint = """
No hint this time
"""
[[exercises]]
name = "grade_calculator"
path = "exercises/control-flow/grade_calculator.nr"
mode = "test"
hint = """
No hint this time
"""
[[exercises]]
name = "count_factors"
path = "exercises/control-flow/count_factors.nr"
mode = "test"
hint = """
No hint this time
"""
# Arrays
[[exercises]]
name = "array_basics"
path = "exercises/arrays/array_basics.nr"
mode = "test"
hint = """
No hint this time
"""
[[exercises]]
name = "array_advance"
path = "exercises/arrays/array_advance.nr"
mode = "test"
hint = """
No hint this time
"""
# Structs
[[exercises]]
name = "structs1"
path = "exercises/structs/structs1.nr"
mode = "test"
hint = """
No hint this time
"""
[[exercises]]
name = "structs2"
path = "exercises/structs/structs2.nr"
mode = "test"
hint = """
No hint this time
"""
[[exercises]]
name = "structs3"
path = "exercises/structs/structs3.nr"
mode = "test"
hint = """
Define Person Struct like this
```
struct Person {
name: str<10>,
age: Field,
home_address: Address,
}
```
First create a home_address like
```
let home_address = Address { street_number: street_num, zip_code: zip };
```
Finally create and resturn Person instance
```
Person { name, age, home_address }
```
"""
[[exercises]]
name = "shopping_cart"
path = "exercises/structs/shopping_cart.nr"
mode = "test"
hint = """
Define `new()` method inside implementation block
```
fn new() -> Cart {
let product = Product { id: 0, price: 0, quantity: 0 };
Cart { items: [product; 3], total_items: 0 }
}
```
Define `add_product` method inside implementation block
```
fn add_product(&mut self, product: Product) -> bool {
if self.total_items as u64 >= 3 {
false
} else {
self.items[self.total_items as u64] = product;
self.total_items = self.total_items + 1;
true
}
}
```
"""
# REFERENCES
[[exercises]]
name = "reference1"
path = "exercises/references/reference1.nr"
mode = "test"
hint = """
```
let temp = *a;
*a = *b;
*b = temp;
```
"""
[[exercises]]
name = "reference2"
path = "exercises/references/reference2.nr"
mode = "test"
hint = """
```
fn increment(&mut self) {
self.value = self.value + self.step;
}
fn update_step(&mut self, new_step: Field) {
self.step = new_step;
}
```
As you may have noticed we are not using dereferce symbol(*) because compiler automatically dereferences the struct
reference when you access its fields. This is called "auto-dereferencing" or "auto-ref/deref".
"""
#SLICES
[[exercises]]
name = "slice1"
path = "exercises/slices/slice1.nr"
mode = "test"
hint = """
```
let mut slice = &[1, 2, 3];
slice = slice.push_back(4);
slice = slice.push_front(0);
```
"""
[[exercises]]
name = "slice2"
path = "exercises/slices/slice2.nr"
mode = "test"
hint = """
1. Use `insert` method to insert element at particular index. `insert` method returns new slice.
```
slice = slice.insert(2, 42);
```
2. Remove element from front using `pop_front` method. This method returns a tuple of removed element and new slice.
let (_, slice) = slice.pop_front();
3. return slice length typecasted as Field.
```
slice.len() as Field
```
"""
[[exercises]]
name = "slice3"
path = "exercises/slices/slice3.nr"
mode = "test"
hint = """
1. First create a new slice of doubled elements using `map` method.
```
let slice1 = input.map(|a| a * 2);
```
2. Filter elements greater than 10 using `filter method`
```
let slice2 = slice1.filter(|a| a as u64 <= 10);
```
3. Return the slice
```
slice2
```
"""
[[exercises]]
name = "slice4"
path = "exercises/slices/slice4.nr"
mode = "test"
hint = """
1. We are going to use `Stats` struct to store sum and count. define initial value for accumulator
```
let acc = Stats { sum: 0, count: 0 };
```
2. Use `fold` method to fold values. Here we are passing closure function that will process each element of slice.
3. Remember to define explicit type in closure for `acc` and `x` as type must be known by this point.
```
let stats = numbers.fold(acc, |acc: Stats, x: Field| Stats { sum: acc.sum + x, count: acc.count + 1 });
```
4. Return the average
```
stats.sum / stats.count
```
"""
[[exercises]]
name = "slice5"
path = "exercises/slices/slice5.nr"
mode = "test"
hint = """
```
let valid_transactions = transactions.filter(|txn: Transaction| txn.valid == true);
let amounts = valid_transactions.map(|txn: Transaction| txn.amount);
let sum = amounts.reduce(|acc: Field,x: Field| acc + x);
```
"""
# TUPLES
[[exercises]]
name = "tuple1"
path = "exercises/tuples/tuple1.nr"
mode = "test"
hint = """
```
let person = (name,age,zip);
person
```
"""
[[exercises]]
name = "tuple2"
path = "exercises/tuples/tuple2.nr"
mode = "test"
hint = """
```
No hint this time
```
"""
# Strings
[[exercises]]
name = "string1"
path = "exercises/strings/string1.nr"
mode = "test"
hint = """
```
if password == "SuperSecret!" {
true
} else {
false
}
```
"""
[[exercises]]
name = "string2"
path = "exercises/strings/string2.nr"
mode = "test"
hint = """
1. First convert string into byte array by calling `as_bytes()`
```
let char_bytes = text.as_bytes();
```
2. Run a loop on byte array to sum the values
```
let mut sum: Field = 0;
for i in 0..5 {
sum = sum + char_bytes[i] as Field;
}
```
3. Return the sum
```
sum as Field
```
"""
# INTEGERS
[[exercises]]
name = "integer1"
path = "exercises/integers/integer1.nr"
mode = "test"
hint = """
```
let kill_assists = wrapping_add(wrapping_mul(kills,2), assists);
if deaths > kill_assists {
0
} else {
kill_assists - deaths
}
```
"""
[[exercises]]
name = "integer2"
path = "exercises/integers/integer2.nr"
mode = "test"
hint = """
"""
# TRAITS
[[exercises]]
name = "traits1"
path = "exercises/traits/traits1.nr"
mode = "test"
hint = """
```
fn area(self) -> Field {
self.width * self.height
}
```
"""
[[exercises]]
name = "traits2"
path = "exercises/traits/traits2.nr"
mode = "test"
hint = """
1. Implement Area trait for Circle
```
impl Area for Circle {
fn area(self) -> Field {
3 * self.radius * self.radius
}
}
```
2. Implement Perimeter trait for Circle
```
impl Perimeter for Circle {
fn perimeter(self) -> Field {
2 * 3 * self.radius
}
}
```
"""
[[exercises]]
name = "traits3"
path = "exercises/traits/traits3.nr"
mode = "test"
hint = """
1. Convert trait implementation
```
impl Convert<Fahrenheit> for Celsius {
fn convert(self) -> Fahrenheit {
let f_temp = self.temp * 9/5 + 32;
Fahrenheit {
temp: f_temp
}
}
}
```
"""
[[exercises]]
name = "traits4"
path = "exercises/traits/traits4.nr"
mode = "test"
hint = """
1. Implement `Counter` trait like this for Number
```
impl Counter for Number {
fn increment(self) -> Self {
Number {
value: self.value + 1
}
}
}
```
"""
[[exercises]]
name = "traits5"
path = "exercises/traits/traits5.nr"
mode = "test"
hint = """
```
fn find_maximum<T>(values: [T; 5]) -> T where T: Maximum {
let mut maximum = values[0];
for i in 1..5 {
maximum = values[i].max(maximum);
}
maximum
}
```
"""