···777777 },
778778 .{
779779 .main_file = "006_strings.zig",
780780- .output = "d=d ha ha ha Major Tom",
780780+ .output = "d=d Major Tom",
781781 .hint = "Each '???' needs something filled in.",
782782 },
783783 .{
+5-8
exercises/005_arrays2.zig
···11//
22-// Zig has some fun array operators.
22+// Zig has one array operators.
33//
44// You can use '++' to concatenate two arrays:
55//
···77// const b = [_]u8{ 3,4 };
88// const c = a ++ b ++ [_]u8{ 5 }; // equals 1 2 3 4 5
99//
1010-// You can use '**' to repeat an array:
1111-//
1212-// const d = [_]u8{ 1,2,3 } ** 2; // equals 1 2 3 1 2 3
1313-//
1414-// Note that both '++' and '**' only operate on arrays while your
1515-// program is _being compiled_. This special time is known in Zig
1010+// Note that '++'' only operate on arrays while your program is
1111+// _being compiled_. This special time is known in Zig
1612// parlance as "comptime" and we'll learn plenty more about that
1713// later.
1814//
···3026 // (Problem 2)
3127 // Please set this array using repetition.
3228 // It should result in: 1 0 0 1 1 0 0 1 1 0 0 1
3333- const bit_pattern = [_]u8{ ??? } ** 3;
2929+ const bit_pattern_unit = [_]u8{ ??? };
3030+ const bit_pattern: [3 * bit_pattern_unit.len]u8 = @bitCast(@as([3][bit_pattern_unit.len]u8, @splat(bit_pattern_unit)));
34313532 // Okay, that's all of the problems. Let's see the results.
3633 //
+1-5
exercises/006_strings.zig
···2727 const d: u8 = ziggy[???];
28282929 // (Problem 2)
3030- // Use the array repeat '**' operator to make "ha ha ha ".
3131- const laugh = "ha " ???;
3232-3333- // (Problem 3)
3430 // Use the array concatenation '++' operator to make "Major Tom".
3531 // (You'll need to add a space as well!)
3632 const major = "Major";
···3834 const major_tom = major ??? tom;
39354036 // That's all the problems. Let's see our results:
4141- std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom });
3737+ std.debug.print("d={u} {s}\n", .{ d, major_tom });
4238 // Keen eyes will notice that we've put 'u' and 's' inside the '{}'
4339 // placeholders in the format string above. This tells the
4440 // print() function to format the values as a UTF-8 character and
+5-6
exercises/058_quiz7.zig
···224224// +---+----------------+----------------+----------+
225225//
226226const HermitsNotebook = struct {
227227- // Remember the array repetition operator `**`? It is no mere
228228- // novelty, it's also a great way to assign multiple items in an
229229- // array without having to list them one by one. Here we use it to
230230- // initialize an array with null values.
231231- entries: [place_count]?NotebookEntry = .{null} ** place_count,
227227+ // Remember the array repetition function @splat()? It is a great way
228228+ // to assign multiple items in an array without having to list them
229229+ // one by one. Here we use it to initialize an array with null values.
230230+ entries: [place_count]?NotebookEntry = @splat(null),
232231233232 // The next entry keeps track of where we are in our "todo" list.
234233 next_entry: u8 = 0,
···409408 // aside memory for the trip and have the hermit's notebook fill
410409 // in the trip from the destination back to the path. Note that
411410 // this is the first time we've actually used the destination!
412412- var trip = [_]?TripItem{null} ** (place_count * 2);
411411+ var trip: [place_count * 2]?TripItem = @splat(null);
413412414413 notebook.getTripTo(trip[0..], destination) catch |err| {
415414 print("Oh no! {}\n", .{err});
···32323333 // We return an array of animals representing the creature. (This is why we
3434 // really needed the 'count' parameter. Arrays need a size.)
3535- var animals: [count]Animal = .{undefined} ** count;
3535+ var animals: [count]Animal = undefined;
3636 var next_animal: usize = 0;
37373838 inline for (fmt) |char| {
+3-5
exercises/075_quiz8.zig
···4848// instead.
4949//
5050// Please fill in the body of this function!
5151-fn makePath(from: *Place, to: *Place, dist: u8) Path {
5252-5353-}
5151+fn makePath(from: *Place, to: *Place, dist: u8) Path {}
54525553// Using our new function, these path definitions take up considerably less
5654// space in our program now!
···9795};
98969997const HermitsNotebook = struct {
100100- entries: [place_count]?NotebookEntry = .{null} ** place_count,
9898+ entries: [place_count]?NotebookEntry = @splat(null),
10199 next_entry: u8 = 0,
102100 end_of_entries: u8 = 0,
103101···193191 }
194192 }
195193196196- var trip = [_]?TripItem{null} ** (place_count * 2);
194194+ var trip: [place_count * 2]?TripItem = @splat(null);
197195198196 notebook.getTripTo(trip[0..], destination) catch |err| {
199197 print("Oh no! {}\n", .{err});
+6-6
patches/patches/005_arrays2.patch
···11---- exercises/005_arrays2.zig 2023-10-03 22:15:22.122241138 +0200
22-+++ answers/005_arrays2.zig 2023-10-05 20:04:06.862763262 +0200
33-@@ -25,12 +25,12 @@
11+--- exercises/005_arrays2.zig 2026-05-04 16:26:32.778330847 +0200
22++++ answers/005_arrays2.zig 2026-05-04 16:26:13.082917974 +0200
33+@@ -21,12 +21,12 @@
44 // (Problem 1)
55 // Please set this array concatenating the two arrays above.
66 // It should result in: 1 3 3 7
···1010 // (Problem 2)
1111 // Please set this array using repetition.
1212 // It should result in: 1 0 0 1 1 0 0 1 1 0 0 1
1313-- const bit_pattern = [_]u8{ ??? } ** 3;
1414-+ const bit_pattern = [_]u8{ 1, 0, 0, 1 } ** 3;
1313+- const bit_pattern_unit = [_]u8{ ??? };
1414++ const bit_pattern_unit = [_]u8{ 1, 0, 0, 1 };
1515+ const bit_pattern: [3 * bit_pattern_unit.len]u8 = @bitCast(@as([3][bit_pattern_unit.len]u8, @splat(bit_pattern_unit)));
15161617 // Okay, that's all of the problems. Let's see the results.
1717- //
+4-9
patches/patches/006_strings.patch
···11---- exercises/006_strings.zig 2023-10-03 22:15:22.122241138 +0200
22-+++ answers/006_strings.zig 2023-10-05 20:04:06.869430053 +0200
33-@@ -24,18 +24,18 @@
11+--- exercises/006_strings.zig 2026-05-04 17:04:31.763821070 +0200
22++++ answers/006_strings.zig 2026-05-04 17:02:11.672866263 +0200
33+@@ -24,14 +24,14 @@
44 // (Problem 1)
55 // Use array square bracket syntax to get the letter 'd' from
66 // the string "stardust" above.
···88+ const d: u8 = ziggy[4];
991010 // (Problem 2)
1111- // Use the array repeat '**' operator to make "ha ha ha ".
1212-- const laugh = "ha " ???;
1313-+ const laugh = "ha " ** 3;
1414-1515- // (Problem 3)
1611 // Use the array concatenation '++' operator to make "Major Tom".
1712 // (You'll need to add a space as well!)
1813 const major = "Major";
···2116+ const major_tom = major ++ " " ++ tom;
22172318 // That's all the problems. Let's see our results:
2424- std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom });
1919+ std.debug.print("d={u} {s}\n", .{ d, major_tom });
+4-4
patches/patches/058_quiz7.patch
···11---- exercises/058_quiz7.zig 2024-10-28 09:06:49.448505460 +0100
22-+++ answers/058_quiz7.zig 2024-10-28 09:35:14.631932322 +0100
11+--- exercises/058_quiz7.zig 2026-05-04 16:34:31.692458399 +0200
22++++ answers/058_quiz7.zig 2026-05-04 16:34:29.239406323 +0200
33@@ -192,8 +192,8 @@
44 // Oops! The hermit forgot how to capture the union values
55 // in a switch statement. Please capture each value as
···1111 }
1212 }
1313 };
1414-@@ -255,7 +255,7 @@
1414+@@ -254,7 +254,7 @@
1515 // dereference and optional value "unwrapping" look
1616 // together. Remember that you return the address with the
1717 // "&" operator.
···2020 // Try to make your answer this long:__________;
2121 }
2222 return null;
2323-@@ -309,7 +309,7 @@
2323+@@ -308,7 +308,7 @@
2424 //
2525 // Looks like the hermit forgot something in the return value of
2626 // this function. What could that be?
+3-3
patches/patches/067_comptime2.patch
···11---- exercises/067_comptime2.zig 2025-12-07 22:51:24.396031248 +0100
22-+++ answers/067_comptime2.zig 2025-12-07 22:50:18.721616293 +0100
11+--- exercises/067_comptime2.zig 2026-05-04 15:38:52.565144012 +0200
22++++ answers/067_comptime2.zig 2026-05-04 15:37:20.257213463 +0200
33@@ -36,7 +36,7 @@
44 // In this contrived example, we've decided to allocate some
55 // arrays using a variable count! But something's missing...
···88+ comptime var count = 0;
991010 count += 1;
1111- const a1: [count]u8 = .{'A'} ** count;
1111+ const a1: [count]u8 = @splat('A');
+3-3
patches/patches/074_comptime9.patch
···11---- exercises/074_comptime9.zig 2026-04-30 19:28:08.990995153 +0200
22-+++ answers/074_comptime9.zig 2026-04-30 19:27:09.642728692 +0200
11+--- exercises/074_comptime9.zig 2026-05-04 17:11:05.144118157 +0200
22++++ answers/074_comptime9.zig 2026-05-04 17:10:36.778519877 +0200
33@@ -28,12 +28,12 @@
44 start, // Ready to start a new animal.
55 l, // This means we've seen an "l", so if we see an "m", we know it's a Llama.
···991010 // We return an array of animals representing the creature. (This is why we
1111 // really needed the 'count' parameter. Arrays need a size.)
1212- var animals: [count]Animal = .{undefined} ** count;
1212+ var animals: [count]Animal = undefined;
1313- var next_animal: usize = 0;
1414+ comptime var next_animal: usize = 0;
1515
+8-6
patches/patches/075_quiz8.patch
···11---- exercises/075_quiz8.zig 2023-11-21 14:48:15.440702720 +0100
22-+++ answers/075_quiz8.zig 2023-11-21 14:50:23.453311616 +0100
33-@@ -49,7 +49,11 @@
11+--- exercises/075_quiz8.zig 2026-05-04 15:51:48.254371574 +0200
22++++ answers/075_quiz8.zig 2026-05-04 15:49:28.426445382 +0200
33+@@ -48,7 +48,13 @@
44+ // instead.
45 //
56 // Please fill in the body of this function!
66- fn makePath(from: *Place, to: *Place, dist: u8) Path {
77--
77+-fn makePath(from: *Place, to: *Place, dist: u8) Path {}
88++fn makePath(from: *Place, to: *Place, dist: u8) Path {
89+ return Path{
910+ .from = from,
1011+ .to = to,
1112+ .dist = dist,
1213+ };
1313- }
1414++}
14151516 // Using our new function, these path definitions take up considerably less
1717+ // space in our program now!
+3-3
patches/patches/110_files2.patch
···11---- exercises/110_files2.zig 2026-03-20 19:23:48.874150121 +0100
22-+++ answers/110_files2.zig 2026-04-02 10:51:15.815831734 +0200
11+--- exercises/110_files2.zig 2026-05-04 17:08:38.913033915 +0200
22++++ answers/110_files2.zig 2026-05-04 17:08:37.112995948 +0200
33@@ -39,7 +39,7 @@
44 // 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
66 // fix the initialization below
77- var content = ['A']*64;
88-+ var content = [_]u8{'A'} ** 64;
88++ var content: [64]u8 = @splat('A');
99 // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`
1010 std.debug.print("{s}\n", .{content});
1111