File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ pub fn build(b: *Build) !void {
200200
201201 if (rand ) | _ | {
202202 // Random build mode: verifies one random exercise.
203- // like for 'exno' but chooses a random exersise number.
203+ // like for 'exno' but chooses a random exercise number.
204204 print ("work in progress: check a random exercise\n " , .{});
205205
206206 var prng = std .Random .DefaultPrng .init (blk : {
Original file line number Diff line number Diff line change 1717//
1818// if (foo) |value| {
1919// ...
20- // } else |err| switch(err) {
20+ // } else |err| switch (err) {
2121// ...
2222// }
2323//
Original file line number Diff line number Diff line change 77// doing this work.
88//
99// An 'inline for' is performed at compile time, allowing you to
10- // programatically loop through a series of items in situations
10+ // programmatically loop through a series of items in situations
1111// like those mentioned above where a regular runtime 'for' loop
1212// wouldn't be allowed:
1313//
Original file line number Diff line number Diff line change 2121// There were the Scottish mathematician Gregory and the German
2222// mathematician Leibniz, and even a few hundred years earlier the Indian
2323// mathematician Madhava. All of them independently developed the same
24- // formula, which was published by Leibnitz in 1682 in the journal
24+ // formula, which was published by Leibniz in 1682 in the journal
2525// "Acta Eruditorum".
26- // This is why this method has become known as the "Leibnitz series",
26+ // This is why this method has become known as the "Leibniz series",
2727// although the other names are also often used today.
2828// We will not go into the formula and its derivation in detail, but
2929// will deal with the series straight away:
5050// enough for us for now, because we want to understand the principle and
5151// nothing more, right?
5252//
53- // As we have already discovered, the Leibnitz series is a series with a
53+ // As we have already discovered, the Leibniz series is a series with a
5454// fixed distance of 2 between the individual partial values. This makes
5555// it easy to apply a simple loop to it, because if we start with n = 1
5656// (which is not necessarily useful now) we always have to add 2 in each
Original file line number Diff line number Diff line change 1212// Alright, bud, lean in close. Here's the game plan.
1313// - First, we open the {project_root}/output/ directory
1414// - Secondly, we open file `zigling.txt` in that directory
15- // - Then, we initalize an array of characters with all letter 'A', and print it
15+ // - Then, we initialize an array of characters with all letter 'A', and print it
1616// - After that, we read the content of the file into the array
1717// - Finally, we print out the content we just read
1818
@@ -30,9 +30,9 @@ pub fn main() !void {
3030 const file = try output_dir .openFile ("zigling.txt" , .{});
3131 defer file .close ();
3232
33- // initalize an array of u8 with all letter 'A'
33+ // initialize an array of u8 with all letter 'A'
3434 // we need to pick the size of the array, 64 seems like a good number
35- // fix the initalization below
35+ // fix the initialization below
3636 var content = ['A' ]* 64 ;
3737 // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`
3838 std .debug .print ("{s}\n " , .{content });
Original file line number Diff line number Diff line change 2424//
2525// By combining all we've learned so far, we can now proceed with a labeled switch
2626//
27- // A labeled switch is some extra syntatic sugar, which comes with all sorts of
27+ // A labeled switch is some extra syntactic sugar, which comes with all sorts of
2828// candy (performance benefits). Don't believe me? Directly to source https://github.com/ziglang/zig/pull/21367
2929//
3030// Here is the previous excerpt implemented as a labeled switch instead:
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ pub fn main() !void {
161161// In order to output a 1, the logic of an XOR operation requires that the
162162// two input bits are of different values. Therefore, 0 ^ 1 and 1 ^ 0 will
163163// both yield a 1 but 0 ^ 0 and 1 ^ 1 will output 0. XOR's unique behavior
164- // of outputing a 0 when both inputs are 1s is what makes it different from
164+ // of outputting a 0 when both inputs are 1s is what makes it different from
165165// the OR operator; it also gives us the ability to toggle bits by putting
166166// 1s into our bitmask.
167167//
@@ -247,7 +247,7 @@ pub fn main() !void {
247247// PORTB = PORTB & 0b1011;
248248// print("PORTB: {b:0>4}\n", .{PORTB}); // output -> 1010
249249//
250- // - 0s clear bits when used in conjuction with a bitwise AND.
250+ // - 0s clear bits when used in conjunction with a bitwise AND.
251251// - 1s do nothing, thus preserving the original bits.
252252//
253253// -AND op- ---expanded---
Original file line number Diff line number Diff line change 11--- exercises/107_files2.zig 2025-03-13 15:26:59.532367792 +0200
22+++ answers/107_files2.zig 2025-03-14 22:08:35.167953736 +0200
33@@ -33,7 +33,7 @@
4- // initalize an array of u8 with all letter 'A'
4+ // initialize an array of u8 with all letter 'A'
55 // we need to pick the size of the array, 64 seems like a good number
6- // fix the initalization below
6+ // fix the initialization below
77- var content = ['A']*64;
88+ var content = [_]u8{'A'} ** 64;
99 // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`
You can’t perform that action at this time.
0 commit comments