From e0259f43a726f61da14686de802021fcdb9aacd0 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Fri, 3 Apr 2026 13:35:56 +0200 Subject: Insert space for additional async exercises --- patches/patches/091_async8.patch | 11 ++++++ patches/patches/092_interfaces.patch | 11 ------ patches/patches/093_hello_c.patch | 11 ------ patches/patches/094_c_math.patch | 11 ------ patches/patches/095_for3.patch | 20 ---------- patches/patches/095_interfaces.patch | 11 ++++++ patches/patches/096_hello_c.patch | 11 ++++++ patches/patches/096_memory_allocation.patch | 11 ------ patches/patches/097_bit_manipulation.patch | 11 ------ patches/patches/097_c_math.patch | 11 ++++++ patches/patches/098_bit_manipulation2.patch | 9 ----- patches/patches/098_for3.patch | 20 ++++++++++ patches/patches/099_formatting.patch | 11 ------ patches/patches/099_memory_allocation.patch | 11 ++++++ patches/patches/100_bit_manipulation.patch | 11 ++++++ patches/patches/100_for4.patch | 11 ------ patches/patches/101_bit_manipulation2.patch | 9 +++++ patches/patches/101_for5.patch | 11 ------ patches/patches/102_formatting.patch | 11 ++++++ patches/patches/102_testing.patch | 18 --------- patches/patches/103_for4.patch | 11 ++++++ patches/patches/103_tokenization.patch | 11 ------ patches/patches/104_for5.patch | 11 ++++++ patches/patches/104_threading.patch | 17 --------- patches/patches/105_testing.patch | 18 +++++++++ patches/patches/105_threading2.patch | 13 ------- patches/patches/106_files.patch | 20 ---------- patches/patches/106_tokenization.patch | 11 ++++++ patches/patches/107_files2.patch | 26 ------------- patches/patches/107_threading.patch | 17 +++++++++ patches/patches/108_labeled_switch.patch | 18 --------- patches/patches/108_threading2.patch | 13 +++++++ patches/patches/109_files.patch | 20 ++++++++++ patches/patches/109_vectors.patch | 13 ------- patches/patches/110_files2.patch | 26 +++++++++++++ patches/patches/110_quiz9.patch | 56 ---------------------------- patches/patches/111_labeled_switch.patch | 18 +++++++++ patches/patches/111_packed.patch | 57 ----------------------------- patches/patches/112_packed2.patch | 32 ---------------- patches/patches/112_vectors.patch | 13 +++++++ patches/patches/113_quiz9.patch | 56 ++++++++++++++++++++++++++++ patches/patches/114_packed.patch | 57 +++++++++++++++++++++++++++++ patches/patches/115_packed2.patch | 32 ++++++++++++++++ 43 files changed, 409 insertions(+), 398 deletions(-) create mode 100644 patches/patches/091_async8.patch delete mode 100644 patches/patches/092_interfaces.patch delete mode 100644 patches/patches/093_hello_c.patch delete mode 100644 patches/patches/094_c_math.patch delete mode 100644 patches/patches/095_for3.patch create mode 100644 patches/patches/095_interfaces.patch create mode 100644 patches/patches/096_hello_c.patch delete mode 100644 patches/patches/096_memory_allocation.patch delete mode 100644 patches/patches/097_bit_manipulation.patch create mode 100644 patches/patches/097_c_math.patch delete mode 100644 patches/patches/098_bit_manipulation2.patch create mode 100644 patches/patches/098_for3.patch delete mode 100644 patches/patches/099_formatting.patch create mode 100644 patches/patches/099_memory_allocation.patch create mode 100644 patches/patches/100_bit_manipulation.patch delete mode 100644 patches/patches/100_for4.patch create mode 100644 patches/patches/101_bit_manipulation2.patch delete mode 100644 patches/patches/101_for5.patch create mode 100644 patches/patches/102_formatting.patch delete mode 100644 patches/patches/102_testing.patch create mode 100644 patches/patches/103_for4.patch delete mode 100644 patches/patches/103_tokenization.patch create mode 100644 patches/patches/104_for5.patch delete mode 100644 patches/patches/104_threading.patch create mode 100644 patches/patches/105_testing.patch delete mode 100644 patches/patches/105_threading2.patch delete mode 100644 patches/patches/106_files.patch create mode 100644 patches/patches/106_tokenization.patch delete mode 100644 patches/patches/107_files2.patch create mode 100644 patches/patches/107_threading.patch delete mode 100644 patches/patches/108_labeled_switch.patch create mode 100644 patches/patches/108_threading2.patch create mode 100644 patches/patches/109_files.patch delete mode 100644 patches/patches/109_vectors.patch create mode 100644 patches/patches/110_files2.patch delete mode 100644 patches/patches/110_quiz9.patch create mode 100644 patches/patches/111_labeled_switch.patch delete mode 100644 patches/patches/111_packed.patch delete mode 100644 patches/patches/112_packed2.patch create mode 100644 patches/patches/112_vectors.patch create mode 100644 patches/patches/113_quiz9.patch create mode 100644 patches/patches/114_packed.patch create mode 100644 patches/patches/115_packed2.patch (limited to 'patches') diff --git a/patches/patches/091_async8.patch b/patches/patches/091_async8.patch new file mode 100644 index 0000000..865292f --- /dev/null +++ b/patches/patches/091_async8.patch @@ -0,0 +1,11 @@ +--- exercises/091_async8.zig 2026-04-02 10:49:27.925721496 +0200 ++++ answers/091_async8.zig 2026-04-02 10:49:31.694795212 +0200 +@@ -43,7 +43,7 @@ + // Send numbers 1 through 10 into the queue. + for (1..11) |i| { + // What Queue method sends a single element, blocking if full? +- queue.???(io, @intCast(i)) catch return; ++ queue.putOne(io, @intCast(i)) catch return; + } + // Signal that we're done sending. + queue.close(io); diff --git a/patches/patches/092_interfaces.patch b/patches/patches/092_interfaces.patch deleted file mode 100644 index 36d8784..0000000 --- a/patches/patches/092_interfaces.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/092_interfaces.zig 2023-10-03 22:15:22.125574535 +0200 -+++ answers/092_interfaces.zig 2023-10-05 20:04:07.259437354 +0200 -@@ -106,7 +106,7 @@ - for (my_insects) |insect| { - // Almost done! We want to print() each insect with a - // single method call here. -- ??? -+ insect.print(); - } - } - diff --git a/patches/patches/093_hello_c.patch b/patches/patches/093_hello_c.patch deleted file mode 100644 index fe1f853..0000000 --- a/patches/patches/093_hello_c.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/093_hello_c.zig 2023-10-03 22:15:22.125574535 +0200 -+++ answers/093_hello_c.zig 2023-10-05 20:04:07.262770750 +0200 -@@ -54,7 +54,7 @@ - // - // In this exercise we use 'write' to output 17 chars, - // but something is still missing... -- const c_res = write(2, "Hello C from Zig!", 17); -+ const c_res = c.write(2, "Hello C from Zig!", 17); - - // let's see what the result from C is: - std.debug.print(" - C result is {d} chars written.\n", .{c_res}); diff --git a/patches/patches/094_c_math.patch b/patches/patches/094_c_math.patch deleted file mode 100644 index f8c7620..0000000 --- a/patches/patches/094_c_math.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/094_c_math.zig 2024-02-28 12:50:35.789939935 +0100 -+++ answers/094_c_math.zig 2024-02-28 12:53:57.910309471 +0100 -@@ -26,7 +26,7 @@ - - const c = @cImport({ - // What do we need here? -- ??? -+ @cInclude("math.h"); - }); - - pub fn main() !void { diff --git a/patches/patches/095_for3.patch b/patches/patches/095_for3.patch deleted file mode 100644 index a158b31..0000000 --- a/patches/patches/095_for3.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- exercises/095_for3.zig 2026-02-27 19:33:59 -+++ answers/095_for3.zig 2026-02-27 19:33:38 -@@ -56,7 +56,7 @@ - - // I want to print every number between 1 and 20 that is NOT - // divisible by 3 or 5. -- for (???) |n| { -+ for (1..21) |n| { - - // The '%' symbol is the "modulo" operator and it - // returns the remainder after division. -@@ -68,7 +68,7 @@ - std.debug.print("\n", .{}); - - // Let's also print every number from 1 through 15 -- for (???) |n| { -+ for (1..16) |n| { - std.debug.print("{} ", .{n}); - } - std.debug.print("\n", .{}); diff --git a/patches/patches/095_interfaces.patch b/patches/patches/095_interfaces.patch new file mode 100644 index 0000000..cb5fd62 --- /dev/null +++ b/patches/patches/095_interfaces.patch @@ -0,0 +1,11 @@ +--- exercises/095_interfaces.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/095_interfaces.zig 2026-04-03 13:09:13.722917764 +0200 +@@ -106,7 +106,7 @@ + for (my_insects) |insect| { + // Almost done! We want to print() each insect with a + // single method call here. +- ??? ++ insect.print(); + } + } + diff --git a/patches/patches/096_hello_c.patch b/patches/patches/096_hello_c.patch new file mode 100644 index 0000000..f5fe06f --- /dev/null +++ b/patches/patches/096_hello_c.patch @@ -0,0 +1,11 @@ +--- exercises/096_hello_c.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/096_hello_c.zig 2026-04-03 13:09:26.195163128 +0200 +@@ -54,7 +54,7 @@ + // + // In this exercise we use 'write' to output 17 chars, + // but something is still missing... +- const c_res = write(2, "Hello C from Zig!", 17); ++ const c_res = c.write(2, "Hello C from Zig!", 17); + + // let's see what the result from C is: + std.debug.print(" - C result is {d} chars written.\n", .{c_res}); diff --git a/patches/patches/096_memory_allocation.patch b/patches/patches/096_memory_allocation.patch deleted file mode 100644 index c26eeeb..0000000 --- a/patches/patches/096_memory_allocation.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/096_memory_allocation.zig 2023-11-21 14:55:33.805678390 +0100 -+++ answers/096_memory_allocation.zig 2023-11-21 14:56:00.236163484 +0100 -@@ -64,7 +64,7 @@ - const allocator = arena.allocator(); - - // allocate memory for this array -- const avg: []f64 = ???; -+ const avg: []f64 = try allocator.alloc(f64, arr.len); - - runningAverage(arr, avg); - std.debug.print("Running Average: ", .{}); diff --git a/patches/patches/097_bit_manipulation.patch b/patches/patches/097_bit_manipulation.patch deleted file mode 100644 index 19ba876..0000000 --- a/patches/patches/097_bit_manipulation.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/097_bit_manipulation.zig 2025-05-12 21:25:03.395385743 +0200 -+++ answers/097_bit_manipulation.zig 2025-05-12 21:22:57.472986976 +0200 -@@ -80,7 +80,7 @@ - y ^= x; - - // What must be written here? -- ???; -+ x ^= y; - - print("x = {b}; y = {b}\n", .{ x, y }); - } diff --git a/patches/patches/097_c_math.patch b/patches/patches/097_c_math.patch new file mode 100644 index 0000000..917fe6b --- /dev/null +++ b/patches/patches/097_c_math.patch @@ -0,0 +1,11 @@ +--- exercises/097_c_math.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/097_c_math.zig 2026-04-03 13:09:32.059278502 +0200 +@@ -26,7 +26,7 @@ + + const c = @cImport({ + // What do we need here? +- ??? ++ @cInclude("math.h"); + }); + + pub fn main() !void { diff --git a/patches/patches/098_bit_manipulation2.patch b/patches/patches/098_bit_manipulation2.patch deleted file mode 100644 index 5354a7b..0000000 --- a/patches/patches/098_bit_manipulation2.patch +++ /dev/null @@ -1,9 +0,0 @@ ---- exercises/098_bit_manipulation2.zig 2023-10-03 22:15:22.125574535 +0200 -+++ answers/098_bit_manipulation2.zig 2023-10-05 20:04:07.286104520 +0200 -@@ -60,5 +60,5 @@ - // and if so, we know the given string is a pangram - // - // but what do we have to compare? -- return bits == 0x..???; -+ return bits == 0x3ffffff; - } diff --git a/patches/patches/098_for3.patch b/patches/patches/098_for3.patch new file mode 100644 index 0000000..c280bc6 --- /dev/null +++ b/patches/patches/098_for3.patch @@ -0,0 +1,20 @@ +--- exercises/098_for3.zig 2026-03-20 19:23:48.873150100 +0100 ++++ answers/098_for3.zig 2026-04-03 13:09:39.916433087 +0200 +@@ -56,7 +56,7 @@ + + // I want to print every number between 1 and 20 that is NOT + // divisible by 3 or 5. +- for (???) |n| { ++ for (1..21) |n| { + + // The '%' symbol is the "modulo" operator and it + // returns the remainder after division. +@@ -68,7 +68,7 @@ + std.debug.print("\n", .{}); + + // Let's also print every number from 1 through 15 +- for (???) |n| { ++ for (1..16) |n| { + std.debug.print("{} ", .{n}); + } + std.debug.print("\n", .{}); diff --git a/patches/patches/099_formatting.patch b/patches/patches/099_formatting.patch deleted file mode 100644 index a56b556..0000000 --- a/patches/patches/099_formatting.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/099_formatting.zig 2024-11-07 21:45:10.459123650 +0100 -+++ answers/099_formatting.zig 2024-11-07 21:43:55.154345991 +0100 -@@ -131,7 +131,7 @@ - for (0..size) |b| { - // What formatting is needed here to make our columns - // nice and straight? -- print("{???} ", .{(a + 1) * (b + 1)}); -+ print("{d:>3} ", .{(a + 1) * (b + 1)}); - } - - // After each row we use double line feed: diff --git a/patches/patches/099_memory_allocation.patch b/patches/patches/099_memory_allocation.patch new file mode 100644 index 0000000..d83a0ae --- /dev/null +++ b/patches/patches/099_memory_allocation.patch @@ -0,0 +1,11 @@ +--- exercises/099_memory_allocation.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/099_memory_allocation.zig 2026-04-03 13:09:47.403580391 +0200 +@@ -64,7 +64,7 @@ + const allocator = arena.allocator(); + + // allocate memory for this array +- const avg: []f64 = ???; ++ const avg: []f64 = try allocator.alloc(f64, arr.len); + + runningAverage(arr, avg); + std.debug.print("Running Average: ", .{}); diff --git a/patches/patches/100_bit_manipulation.patch b/patches/patches/100_bit_manipulation.patch new file mode 100644 index 0000000..f70cc41 --- /dev/null +++ b/patches/patches/100_bit_manipulation.patch @@ -0,0 +1,11 @@ +--- exercises/100_bit_manipulation.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/100_bit_manipulation.zig 2026-04-02 10:51:15.795831343 +0200 +@@ -80,7 +80,7 @@ + y ^= x; + + // What must be written here? +- ???; ++ x ^= y; + + print("x = {b}; y = {b}\n", .{ x, y }); + } diff --git a/patches/patches/100_for4.patch b/patches/patches/100_for4.patch deleted file mode 100644 index ad73e9a..0000000 --- a/patches/patches/100_for4.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/100_for4.zig 2023-10-03 22:15:22.125574535 +0200 -+++ answers/100_for4.zig 2023-10-05 20:04:07.296104707 +0200 -@@ -39,7 +39,7 @@ - const hex_nums = [_]u8{ 0xb, 0x2a, 0x77 }; - const dec_nums = [_]u8{ 11, 42, 119 }; - -- for (hex_nums, ???) |hn, ???| { -+ for (hex_nums, dec_nums) |hn, dn| { - if (hn != dn) { - print("Uh oh! Found a mismatch: {d} vs {d}\n", .{ hn, dn }); - return; diff --git a/patches/patches/101_bit_manipulation2.patch b/patches/patches/101_bit_manipulation2.patch new file mode 100644 index 0000000..5179272 --- /dev/null +++ b/patches/patches/101_bit_manipulation2.patch @@ -0,0 +1,9 @@ +--- exercises/101_bit_manipulation2.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/101_bit_manipulation2.zig 2026-04-02 10:51:15.797831382 +0200 +@@ -60,5 +60,5 @@ + // and if so, we know the given string is a pangram + // + // but what do we have to compare? +- return bits == 0x..???; ++ return bits == 0x3ffffff; + } diff --git a/patches/patches/101_for5.patch b/patches/patches/101_for5.patch deleted file mode 100644 index 00f19df..0000000 --- a/patches/patches/101_for5.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/101_for5.zig 2023-10-03 22:15:22.125574535 +0200 -+++ answers/101_for5.zig 2023-10-05 20:04:07.299438103 +0200 -@@ -51,7 +51,7 @@ - - // We would like to number our list starting with 1, not 0. - // How do we do that? -- for (roles, gold, experience, ???) |c, g, e, i| { -+ for (roles, gold, experience, 1..) |c, g, e, i| { - const role_name = switch (c) { - .wizard => "Wizard", - .thief => "Thief", diff --git a/patches/patches/102_formatting.patch b/patches/patches/102_formatting.patch new file mode 100644 index 0000000..dba8aef --- /dev/null +++ b/patches/patches/102_formatting.patch @@ -0,0 +1,11 @@ +--- exercises/102_formatting.zig 2026-03-20 19:23:48.873150100 +0100 ++++ answers/102_formatting.zig 2026-04-02 10:51:15.799831421 +0200 +@@ -131,7 +131,7 @@ + for (0..size) |b| { + // What formatting is needed here to make our columns + // nice and straight? +- print("{???} ", .{(a + 1) * (b + 1)}); ++ print("{d:>3} ", .{(a + 1) * (b + 1)}); + } + + // After each row we use double line feed: diff --git a/patches/patches/102_testing.patch b/patches/patches/102_testing.patch deleted file mode 100644 index 6d18bf6..0000000 --- a/patches/patches/102_testing.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- exercises/102_testing.zig 2025-10-24 12:54:56 -+++ answers/102_testing.zig 2025-10-24 12:56:33 -@@ -71,7 +71,7 @@ - // The corresponding test is not much different from the previous one. Except - // that it contains an error that you need to correct. - test "sub" { -- try testing.expect(sub(10, 5) == 6); -+ try testing.expect(sub(10, 5) == 5); - - try testing.expect(sub(3, 1.5) == 1.5); - } -@@ -92,5 +92,5 @@ - - // Now we test if the function returns an error if we pass a zero as - // denominator. But which error needs to be tested? -- try testing.expectError(error.???, divide(15, 0)); -+ try testing.expectError(error.DivisionByZero, divide(15, 0)); - } diff --git a/patches/patches/103_for4.patch b/patches/patches/103_for4.patch new file mode 100644 index 0000000..7a7e161 --- /dev/null +++ b/patches/patches/103_for4.patch @@ -0,0 +1,11 @@ +--- exercises/103_for4.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/103_for4.zig 2026-04-02 10:51:15.801831460 +0200 +@@ -39,7 +39,7 @@ + const hex_nums = [_]u8{ 0xb, 0x2a, 0x77 }; + const dec_nums = [_]u8{ 11, 42, 119 }; + +- for (hex_nums, ???) |hn, ???| { ++ for (hex_nums, dec_nums) |hn, dn| { + if (hn != dn) { + print("Uh oh! Found a mismatch: {d} vs {d}\n", .{ hn, dn }); + return; diff --git a/patches/patches/103_tokenization.patch b/patches/patches/103_tokenization.patch deleted file mode 100644 index 941ca3b..0000000 --- a/patches/patches/103_tokenization.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- exercises/103_tokenization.zig 2026-02-27 19:25:11 -+++ answers/103_tokenization.zig 2026-02-27 19:26:04 -@@ -134,7 +134,7 @@ - ; - - // now the tokenizer, but what do we need here? -- var it = std.mem.tokenizeAny(u8, poem, ???); -+ var it = std.mem.tokenizeAny(u8, poem, " ,;!\n"); - - // print all words and count them - var cnt: usize = 0; diff --git a/patches/patches/104_for5.patch b/patches/patches/104_for5.patch new file mode 100644 index 0000000..ef77013 --- /dev/null +++ b/patches/patches/104_for5.patch @@ -0,0 +1,11 @@ +--- exercises/104_for5.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/104_for5.zig 2026-04-02 10:51:15.803831499 +0200 +@@ -51,7 +51,7 @@ + + // We would like to number our list starting with 1, not 0. + // How do we do that? +- for (roles, gold, experience, ???) |c, g, e, i| { ++ for (roles, gold, experience, 1..) |c, g, e, i| { + const role_name = switch (c) { + .wizard => "Wizard", + .thief => "Thief", diff --git a/patches/patches/104_threading.patch b/patches/patches/104_threading.patch deleted file mode 100644 index e6fe0f4..0000000 --- a/patches/patches/104_threading.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- exercises/104_threading.zig 2026-04-01 23:31:10.073198955 +0200 -+++ answers/104_threading.zig 2026-04-01 23:29:51.314585919 +0200 -@@ -88,12 +88,12 @@ - defer handle.join(); - - // Second thread -- const handle2 = try std.Thread.spawn(.{}, thread_function, .{-4}); // that can't be right? -+ const handle2 = try std.Thread.spawn(.{}, thread_function, .{2}); - defer handle2.join(); - - // Third thread - const handle3 = try std.Thread.spawn(.{}, thread_function, .{3}); -- defer ??? // <-- something is missing -+ defer handle3.join(); - - // After the threads have been started, - // they run in parallel and we can still do some work in between. diff --git a/patches/patches/105_testing.patch b/patches/patches/105_testing.patch new file mode 100644 index 0000000..069b72b --- /dev/null +++ b/patches/patches/105_testing.patch @@ -0,0 +1,18 @@ +--- exercises/105_testing.zig 2026-03-20 19:23:48.873150100 +0100 ++++ answers/105_testing.zig 2026-04-02 10:51:15.805831538 +0200 +@@ -71,7 +71,7 @@ + // The corresponding test is not much different from the previous one. Except + // that it contains an error that you need to correct. + test "sub" { +- try testing.expect(sub(10, 5) == 6); ++ try testing.expect(sub(10, 5) == 5); + + try testing.expect(sub(3, 1.5) == 1.5); + } +@@ -92,5 +92,5 @@ + + // Now we test if the function returns an error if we pass a zero as + // denominator. But which error needs to be tested? +- try testing.expectError(error.???, divide(15, 0)); ++ try testing.expectError(error.DivisionByZero, divide(15, 0)); + } diff --git a/patches/patches/105_threading2.patch b/patches/patches/105_threading2.patch deleted file mode 100644 index dfa5613..0000000 --- a/patches/patches/105_threading2.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- exercises/105_threading2.zig 2024-03-23 16:35:14.754540802 +0100 -+++ answers/105_threading2.zig 2024-03-23 16:38:00.577539733 +0100 -@@ -81,8 +81,8 @@ - defer handle1.join(); - - // Second thread to calculate the minus numbers. -- ??? -- -+ const handle2 = try std.Thread.spawn(.{}, thread_pi, .{ &pi_minus, 3, count }); -+ defer handle2.join(); - } - // Here we add up the results. - std.debug.print("PI ≈ {d:.8}\n", .{4 + pi_plus - pi_minus}); diff --git a/patches/patches/106_files.patch b/patches/patches/106_files.patch deleted file mode 100644 index 27bcb56..0000000 --- a/patches/patches/106_files.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- exercises/106_files.zig 2026-01-09 22:41:19.373872684 +0100 -+++ answers/106_files.zig 2026-01-09 22:41:44.518372910 +0100 -@@ -41,7 +41,7 @@ - // by doing nothing - // - // we want to catch error.PathAlreadyExists and do nothing -- ??? => {}, -+ error.PathAlreadyExists => {}, - // if there's any other unexpected error we just propagate it through - else => return e, - }; -@@ -61,7 +61,7 @@ - // but here we are not yet done writing to the file - // if only there were a keyword in Zig that - // allowed you to "defer" code execution to the end of the scope... -- file.close(io); -+ defer file.close(io); - - // you are not allowed to move these lines above the file closing line! - var file_writer = file.writer(io, &.{}); diff --git a/patches/patches/106_tokenization.patch b/patches/patches/106_tokenization.patch new file mode 100644 index 0000000..4792df6 --- /dev/null +++ b/patches/patches/106_tokenization.patch @@ -0,0 +1,11 @@ +--- exercises/106_tokenization.zig 2026-03-20 19:23:48.873150100 +0100 ++++ answers/106_tokenization.zig 2026-04-02 10:51:15.807831578 +0200 +@@ -134,7 +134,7 @@ + ; + + // now the tokenizer, but what do we need here? +- var it = std.mem.tokenizeAny(u8, poem, ???); ++ var it = std.mem.tokenizeAny(u8, poem, " ,;!\n"); + + // print all words and count them + var cnt: usize = 0; diff --git a/patches/patches/107_files2.patch b/patches/patches/107_files2.patch deleted file mode 100644 index 6820742..0000000 --- a/patches/patches/107_files2.patch +++ /dev/null @@ -1,26 +0,0 @@ ---- exercises/107_files2.zig 2026-01-09 22:43:15.211177186 +0100 -+++ answers/107_files2.zig 2026-01-09 22:42:48.943654602 +0100 -@@ -39,7 +39,7 @@ - // initialize an array of u8 with all letter 'A' - // we need to pick the size of the array, 64 seems like a good number - // fix the initialization below -- var content = ['A']*64; -+ var content = [_]u8{'A'} ** 64; - // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA` - std.debug.print("{s}\n", .{content}); - -@@ -50,12 +50,12 @@ - // can you go here to find a way to read the content? - // https://ziglang.org/documentation/master/std/#std.Io.Reader - // hint: look for a method that reads into a slice -- const bytes_read = zig_read_the_file_or_i_will_fight_you(&content); -+ const bytes_read = try reader.readSliceShort(&content); - - // Woah, too screamy. I know you're excited for zigling time but tone it down a bit. - // Can you print only what we read from the file? - std.debug.print("Successfully Read {d} bytes: {s}\n", .{ - bytes_read, -- content, // change this line only -+ content[0..bytes_read], // change this line only - }); - } diff --git a/patches/patches/107_threading.patch b/patches/patches/107_threading.patch new file mode 100644 index 0000000..3f65ef4 --- /dev/null +++ b/patches/patches/107_threading.patch @@ -0,0 +1,17 @@ +--- exercises/107_threading.zig 2026-04-01 23:31:10.073198955 +0200 ++++ answers/107_threading.zig 2026-04-02 10:51:15.809831617 +0200 +@@ -88,12 +88,12 @@ + defer handle.join(); + + // Second thread +- const handle2 = try std.Thread.spawn(.{}, thread_function, .{-4}); // that can't be right? ++ const handle2 = try std.Thread.spawn(.{}, thread_function, .{2}); + defer handle2.join(); + + // Third thread + const handle3 = try std.Thread.spawn(.{}, thread_function, .{3}); +- defer ??? // <-- something is missing ++ defer handle3.join(); + + // After the threads have been started, + // they run in parallel and we can still do some work in between. diff --git a/patches/patches/108_labeled_switch.patch b/patches/patches/108_labeled_switch.patch deleted file mode 100644 index fa9dd67..0000000 --- a/patches/patches/108_labeled_switch.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- exercises/108_labeled_switch.zig 2024-09-20 12:09:24.370066539 +0200 -+++ answers/108_labeled_switch.zig 2024-09-20 12:09:06.499711739 +0200 -@@ -65,13 +65,13 @@ - // how would you fix it? - pr: switch (PullRequestState.Draft) { - PullRequestState.Draft => continue :pr PullRequestState.InReview, -- PullRequestState.InReview => continue :pr PullRequestState.Rejected, -+ PullRequestState.InReview => continue :pr PullRequestState.Approved, - PullRequestState.Approved => continue :pr PullRequestState.Merged, - PullRequestState.Rejected => { - std.debug.print("The pull request has been rejected.\n", .{}); - return; - }, -- PullRequestState.Merged => break, // Would you know where to break to? -+ PullRequestState.Merged => break :pr, // Would you know where to break to? - } - std.debug.print("The pull request has been merged.\n", .{}); - } diff --git a/patches/patches/108_threading2.patch b/patches/patches/108_threading2.patch new file mode 100644 index 0000000..d71f254 --- /dev/null +++ b/patches/patches/108_threading2.patch @@ -0,0 +1,13 @@ +--- exercises/108_threading2.zig 2025-08-15 15:17:57.839348063 +0200 ++++ answers/108_threading2.zig 2026-04-02 10:51:15.811831656 +0200 +@@ -81,8 +81,8 @@ + defer handle1.join(); + + // Second thread to calculate the minus numbers. +- ??? +- ++ const handle2 = try std.Thread.spawn(.{}, thread_pi, .{ &pi_minus, 3, count }); ++ defer handle2.join(); + } + // Here we add up the results. + std.debug.print("PI ≈ {d:.8}\n", .{4 + pi_plus - pi_minus}); diff --git a/patches/patches/109_files.patch b/patches/patches/109_files.patch new file mode 100644 index 0000000..ac59d70 --- /dev/null +++ b/patches/patches/109_files.patch @@ -0,0 +1,20 @@ +--- exercises/109_files.zig 2026-03-20 19:23:48.874150121 +0100 ++++ answers/109_files.zig 2026-04-02 10:51:15.813831695 +0200 +@@ -41,7 +41,7 @@ + // by doing nothing + // + // we want to catch error.PathAlreadyExists and do nothing +- ??? => {}, ++ error.PathAlreadyExists => {}, + // if there's any other unexpected error we just propagate it through + else => return e, + }; +@@ -61,7 +61,7 @@ + // but here we are not yet done writing to the file + // if only there were a keyword in Zig that + // allowed you to "defer" code execution to the end of the scope... +- file.close(io); ++ defer file.close(io); + + // you are not allowed to move these lines above the file closing line! + var file_writer = file.writer(io, &.{}); diff --git a/patches/patches/109_vectors.patch b/patches/patches/109_vectors.patch deleted file mode 100644 index bf18cc0..0000000 --- a/patches/patches/109_vectors.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- exercises/109_vectors.zig 2024-11-07 14:57:09.673383618 +0100 -+++ answers/109_vectors.zig 2024-11-07 14:22:59.069150138 +0100 -@@ -121,8 +121,8 @@ - - const Vec4 = @Vector(4, f32); - fn calcMaxPairwiseDiffNew(a: Vec4, b: Vec4) f32 { -- const abs_diff_vec = ???; -- const max_diff = @reduce(???, abs_diff_vec); -+ const abs_diff_vec = @abs(a - b); -+ const max_diff = @reduce(.Max, abs_diff_vec); - return max_diff; - } - diff --git a/patches/patches/110_files2.patch b/patches/patches/110_files2.patch new file mode 100644 index 0000000..64dc193 --- /dev/null +++ b/patches/patches/110_files2.patch @@ -0,0 +1,26 @@ +--- exercises/110_files2.zig 2026-03-20 19:23:48.874150121 +0100 ++++ answers/110_files2.zig 2026-04-02 10:51:15.815831734 +0200 +@@ -39,7 +39,7 @@ + // initialize an array of u8 with all letter 'A' + // we need to pick the size of the array, 64 seems like a good number + // fix the initialization below +- var content = ['A']*64; ++ var content = [_]u8{'A'} ** 64; + // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA` + std.debug.print("{s}\n", .{content}); + +@@ -50,12 +50,12 @@ + // can you go here to find a way to read the content? + // https://ziglang.org/documentation/master/std/#std.Io.Reader + // hint: look for a method that reads into a slice +- const bytes_read = zig_read_the_file_or_i_will_fight_you(&content); ++ const bytes_read = try reader.readSliceShort(&content); + + // Woah, too screamy. I know you're excited for zigling time but tone it down a bit. + // Can you print only what we read from the file? + std.debug.print("Successfully Read {d} bytes: {s}\n", .{ + bytes_read, +- content, // change this line only ++ content[0..bytes_read], // change this line only + }); + } diff --git a/patches/patches/110_quiz9.patch b/patches/patches/110_quiz9.patch deleted file mode 100644 index 9d9b864..0000000 --- a/patches/patches/110_quiz9.patch +++ /dev/null @@ -1,56 +0,0 @@ ---- exercises/110_quiz9.zig 2025-02-08 13:19:48.522641785 -0800 -+++ answers/110_quiz9.zig 2025-02-10 17:42:04.525004335 -0800 -@@ -108,7 +108,7 @@ - PORTB = 0b1100; - print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); - print("^ {b:0>4} // (bitmask)\n", .{0b0101}); -- PORTB ^= (1 << 1) | (1 << 0); // What's wrong here? -+ PORTB ^= (1 << 2) | (1 << 0); - checkAnswer(0b1001, PORTB); - - newline(); -@@ -116,7 +116,7 @@ - PORTB = 0b1100; - print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); - print("^ {b:0>4} // (bitmask)\n", .{0b0011}); -- PORTB ^= (1 << 1) & (1 << 0); // What's wrong here? -+ PORTB ^= (1 << 1) | (1 << 0); - checkAnswer(0b1111, PORTB); - - newline(); -@@ -170,7 +170,7 @@ - PORTB = 0b1001; // reset PORTB - print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); - print("| {b:0>4} // (bitmask)\n", .{0b0100}); -- PORTB = PORTB ??? (1 << 2); // What's missing here? -+ PORTB = PORTB | (1 << 2); - checkAnswer(0b1101, PORTB); - - newline(); -@@ -178,7 +178,7 @@ - PORTB = 0b1001; // reset PORTB - print(" {b:0>4} // (reset state)\n", .{PORTB}); - print("| {b:0>4} // (bitmask)\n", .{0b0100}); -- PORTB ??? (1 << 2); // What's missing here? -+ PORTB |= (1 << 2); - checkAnswer(0b1101, PORTB); - - newline(); -@@ -269,7 +269,7 @@ - PORTB = 0b1110; // reset PORTB - print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); - print("& {b:0>4} // (bitmask)\n", .{0b1011}); -- PORTB = PORTB & ???@as(u4, 1 << 2); // What character is missing here? -+ PORTB = PORTB & ~@as(u4, 1 << 2); - checkAnswer(0b1010, PORTB); - - newline(); -@@ -277,7 +277,7 @@ - PORTB = 0b0111; // reset PORTB - print(" {b:0>4} // (reset state)\n", .{PORTB}); - print("& {b:0>4} // (bitmask)\n", .{0b1110}); -- PORTB &= ~(1 << 0); // What's missing here? -+ PORTB &= ~@as(u4, 1 << 0); - checkAnswer(0b0110, PORTB); - - newline(); diff --git a/patches/patches/111_labeled_switch.patch b/patches/patches/111_labeled_switch.patch new file mode 100644 index 0000000..0fb872d --- /dev/null +++ b/patches/patches/111_labeled_switch.patch @@ -0,0 +1,18 @@ +--- exercises/111_labeled_switch.zig 2025-08-15 15:17:57.840348083 +0200 ++++ answers/111_labeled_switch.zig 2026-04-02 10:51:15.817831773 +0200 +@@ -67,13 +67,13 @@ + // how would you fix it? + pr: switch (PullRequestState.Draft) { + PullRequestState.Draft => continue :pr PullRequestState.InReview, +- PullRequestState.InReview => continue :pr PullRequestState.Rejected, ++ PullRequestState.InReview => continue :pr PullRequestState.Approved, + PullRequestState.Approved => continue :pr PullRequestState.Merged, + PullRequestState.Rejected => { + std.debug.print("The pull request has been rejected.\n", .{}); + return; + }, +- PullRequestState.Merged => break, // Would you know where to break to? ++ PullRequestState.Merged => break :pr, // Would you know where to break to? + } + std.debug.print("The pull request has been merged.\n", .{}); + } diff --git a/patches/patches/111_packed.patch b/patches/patches/111_packed.patch deleted file mode 100644 index d38ac68..0000000 --- a/patches/patches/111_packed.patch +++ /dev/null @@ -1,57 +0,0 @@ ---- exercises/111_packed.zig 2026-03-13 11:18:44 -+++ answers/111_packed.zig 2026-03-13 11:18:57 -@@ -41,7 +41,7 @@ - - const PackedStruct = packed struct { - a: u2, -- b: u?, -+ b: u4, - }; - - comptime { -@@ -50,7 +50,7 @@ - - const PackedUnion = packed union { - a: bool, -- b: u?, -+ b: u1, - }; - - comptime { -@@ -113,31 +113,31 @@ - pub fn main() void { - { - const expected: Bits = @bitCast(@as(u4, 0b1000)); -- const my_bits: Bits = .{}; -+ const my_bits: Bits = .{ .d = 1 }; - if (my_bits != expected) complain(my_bits, expected, @src()); - } - - { - const expected: Bits = @bitCast(@as(u4, 0b0001)); -- const my_bits: Bits = .{}; -+ const my_bits: Bits = .{ .a = 1 }; - if (my_bits != expected) complain(my_bits, expected, @src()); - } - - { - const expected: Bits = @bitCast(@as(u4, 0b0010)); -- const my_bits: Bits = .{}; -+ const my_bits: Bits = .{ .b = 1 }; - if (my_bits != expected) complain(my_bits, expected, @src()); - } - - { - const expected: Bits = @bitCast(@as(u4, 0b0011)); -- const my_bits: Bits = .{}; -+ const my_bits: Bits = .{ .a = 1, .b = 1 }; - if (my_bits != expected) complain(my_bits, expected, @src()); - } - - { - const expected: Bits = @bitCast(@as(u4, 0b1101)); -- const my_bits: Bits = .{}; -+ const my_bits: Bits = .{ .a = 1, .c = 1, .d = 1 }; - if (my_bits != expected) complain(my_bits, expected, @src()); - } - } diff --git a/patches/patches/112_packed2.patch b/patches/patches/112_packed2.patch deleted file mode 100644 index 9b01eb3..0000000 --- a/patches/patches/112_packed2.patch +++ /dev/null @@ -1,32 +0,0 @@ ---- exercises/112_packed2.zig 2026-03-13 11:14:08 -+++ answers/112_packed2.zig 2026-03-13 11:14:16 -@@ -13,9 +13,9 @@ - const s: S = .{ .a = true, .b = -1 }; - switch (s) { - .{ .a = true, .b = -1 } => {}, // ok! -- .{ .a = true, .b = ??? }, -- .{ .a = ???, .b = 0 }, -- .{ .a = ???, .b = ??? }, -+ .{ .a = true, .b = 0 }, -+ .{ .a = false, .b = 0 }, -+ .{ .a = false, .b = -1 }, - => @compileError("We don't want to end up here!"), - } - } -@@ -39,7 +39,6 @@ - .{ .a = 3 } => {}, // ok! - .{ .a = 2 }, - .{ .b = 1 }, -- .{ .b = -1 }, - .{ .a = 0 }, - => @compileError("We don't want to end up here!"), - } -@@ -65,7 +64,7 @@ - // Reminder: if the sign bit of a float is set, the number is negative! - - var number: Float = .{ .value = 2.34 }; -- number.bits.??? = ???; -+ number.bits.sign = 1; - if (number.value != -2.34) { - std.debug.print("Make it negative!\n", .{}); - } diff --git a/patches/patches/112_vectors.patch b/patches/patches/112_vectors.patch new file mode 100644 index 0000000..5bf684b --- /dev/null +++ b/patches/patches/112_vectors.patch @@ -0,0 +1,13 @@ +--- exercises/112_vectors.zig 2025-08-15 15:17:57.840348083 +0200 ++++ answers/112_vectors.zig 2026-04-02 10:51:15.819831812 +0200 +@@ -121,8 +121,8 @@ + + const Vec4 = @Vector(4, f32); + fn calcMaxPairwiseDiffNew(a: Vec4, b: Vec4) f32 { +- const abs_diff_vec = ???; +- const max_diff = @reduce(???, abs_diff_vec); ++ const abs_diff_vec = @abs(a - b); ++ const max_diff = @reduce(.Max, abs_diff_vec); + return max_diff; + } + diff --git a/patches/patches/113_quiz9.patch b/patches/patches/113_quiz9.patch new file mode 100644 index 0000000..03bd572 --- /dev/null +++ b/patches/patches/113_quiz9.patch @@ -0,0 +1,56 @@ +--- exercises/113_quiz9.zig 2025-08-15 15:17:57.840348083 +0200 ++++ answers/113_quiz9.zig 2026-04-02 10:51:15.821831851 +0200 +@@ -84,7 +84,7 @@ + PORTB = 0b1100; + print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); + print("^ {b:0>4} // (bitmask)\n", .{0b0101}); +- PORTB ^= (1 << 1) | (1 << 0); // What's wrong here? ++ PORTB ^= (1 << 2) | (1 << 0); + checkAnswer(0b1001, PORTB); + + newline(); +@@ -92,7 +92,7 @@ + PORTB = 0b1100; + print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); + print("^ {b:0>4} // (bitmask)\n", .{0b0011}); +- PORTB ^= (1 << 1) & (1 << 0); // What's wrong here? ++ PORTB ^= (1 << 1) | (1 << 0); + checkAnswer(0b1111, PORTB); + + newline(); +@@ -103,7 +103,7 @@ + PORTB = 0b1001; // reset PORTB + print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); + print("| {b:0>4} // (bitmask)\n", .{0b0100}); +- PORTB = PORTB ??? (1 << 2); // What's missing here? ++ PORTB = PORTB | (1 << 2); + checkAnswer(0b1101, PORTB); + + newline(); +@@ -111,7 +111,7 @@ + PORTB = 0b1001; // reset PORTB + print(" {b:0>4} // (reset state)\n", .{PORTB}); + print("| {b:0>4} // (bitmask)\n", .{0b0100}); +- PORTB ??? (1 << 2); // What's missing here? ++ PORTB |= (1 << 2); + checkAnswer(0b1101, PORTB); + + newline(); +@@ -122,7 +122,7 @@ + PORTB = 0b1110; // reset PORTB + print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB}); + print("& {b:0>4} // (bitmask)\n", .{0b1011}); +- PORTB = PORTB & ???@as(u4, 1 << 2); // What character is missing here? ++ PORTB = PORTB & ~@as(u4, 1 << 2); + checkAnswer(0b1010, PORTB); + + newline(); +@@ -130,7 +130,7 @@ + PORTB = 0b0111; // reset PORTB + print(" {b:0>4} // (reset state)\n", .{PORTB}); + print("& {b:0>4} // (bitmask)\n", .{0b1110}); +- PORTB &= ~(1 << 0); // What's missing here? ++ PORTB &= ~@as(u4, 1 << 0); + checkAnswer(0b0110, PORTB); + + newline(); diff --git a/patches/patches/114_packed.patch b/patches/patches/114_packed.patch new file mode 100644 index 0000000..3c79f18 --- /dev/null +++ b/patches/patches/114_packed.patch @@ -0,0 +1,57 @@ +--- exercises/114_packed.zig 2026-03-20 19:23:48.874150121 +0100 ++++ answers/114_packed.zig 2026-04-02 10:51:15.824831910 +0200 +@@ -41,7 +41,7 @@ + + const PackedStruct = packed struct { + a: u2, +- b: u?, ++ b: u4, + }; + + comptime { +@@ -50,7 +50,7 @@ + + const PackedUnion = packed union { + a: bool, +- b: u?, ++ b: u1, + }; + + comptime { +@@ -113,31 +113,31 @@ + pub fn main() void { + { + const expected: Bits = @bitCast(@as(u4, 0b1000)); +- const my_bits: Bits = .{}; ++ const my_bits: Bits = .{ .d = 1 }; + if (my_bits != expected) complain(my_bits, expected, @src()); + } + + { + const expected: Bits = @bitCast(@as(u4, 0b0001)); +- const my_bits: Bits = .{}; ++ const my_bits: Bits = .{ .a = 1 }; + if (my_bits != expected) complain(my_bits, expected, @src()); + } + + { + const expected: Bits = @bitCast(@as(u4, 0b0010)); +- const my_bits: Bits = .{}; ++ const my_bits: Bits = .{ .b = 1 }; + if (my_bits != expected) complain(my_bits, expected, @src()); + } + + { + const expected: Bits = @bitCast(@as(u4, 0b0011)); +- const my_bits: Bits = .{}; ++ const my_bits: Bits = .{ .a = 1, .b = 1 }; + if (my_bits != expected) complain(my_bits, expected, @src()); + } + + { + const expected: Bits = @bitCast(@as(u4, 0b1101)); +- const my_bits: Bits = .{}; ++ const my_bits: Bits = .{ .a = 1, .c = 1, .d = 1 }; + if (my_bits != expected) complain(my_bits, expected, @src()); + } + } diff --git a/patches/patches/115_packed2.patch b/patches/patches/115_packed2.patch new file mode 100644 index 0000000..81c32ab --- /dev/null +++ b/patches/patches/115_packed2.patch @@ -0,0 +1,32 @@ +--- exercises/115_packed2.zig 2026-03-20 19:23:48.874150121 +0100 ++++ answers/115_packed2.zig 2026-04-02 10:51:15.826831949 +0200 +@@ -13,9 +13,9 @@ + const s: S = .{ .a = true, .b = -1 }; + switch (s) { + .{ .a = true, .b = -1 } => {}, // ok! +- .{ .a = true, .b = ??? }, +- .{ .a = ???, .b = 0 }, +- .{ .a = ???, .b = ??? }, ++ .{ .a = true, .b = 0 }, ++ .{ .a = false, .b = 0 }, ++ .{ .a = false, .b = -1 }, + => @compileError("We don't want to end up here!"), + } + } +@@ -39,7 +39,6 @@ + .{ .a = 3 } => {}, // ok! + .{ .a = 2 }, + .{ .b = 1 }, +- .{ .b = -1 }, + .{ .a = 0 }, + => @compileError("We don't want to end up here!"), + } +@@ -65,7 +64,7 @@ + // Reminder: if the sign bit of a float is set, the number is negative! + + var number: Float = .{ .value = 2.34 }; +- number.bits.??? = ???; ++ number.bits.sign = 1; + if (number.value != -2.34) { + std.debug.print("Make it negative!\n", .{}); + } -- cgit v1.2.3