aboutsummaryrefslogtreecommitdiff
path: root/05_arrays2.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-02-07 11:06:51 -0500
committerDave Gauer <dave@ratfactor.com>2021-02-07 11:06:51 -0500
commitadf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a (patch)
treea25511c3bb20069f1d6123366573c82c5745338b /05_arrays2.zig
parent507355ec3b1066c707e19816b86ac1fb56fc0385 (diff)
downloadziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.gz
ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.bz2
ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.xz
ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.zip
Consistent instructions and examples
I started off with "hints" that required the poor student to piece together the information from incomplete bits. A complete example is like a picture that is worth 1000 words and far clearer.
Diffstat (limited to '05_arrays2.zig')
-rw-r--r--05_arrays2.zig19
1 files changed, 13 insertions, 6 deletions
diff --git a/05_arrays2.zig b/05_arrays2.zig
index c021096..9282a31 100644
--- a/05_arrays2.zig
+++ b/05_arrays2.zig
@@ -2,12 +2,14 @@
// Zig has some fun array operators.
//
// You can use '++' to concatenate two arrays:
+//
// const a = [_]u8{ 1,2 };
// const b = [_]u8{ 3,4 };
-// const c = a ++ b ++ [_]u8{ 5 }; // 1,2,3,4,5
+// const c = a ++ b ++ [_]u8{ 5 }; // equals 1 2 3 4 5
//
// You can use '**' to repeat an array:
-// const d = [_]u8{ 1,2,3 } ** 2; // 1,2,3,1,2,3
+//
+// const d = [_]u8{ 1,2,3 } ** 2; // equals 1 2 3 1 2 3
//
const std = @import("std");
@@ -15,15 +17,20 @@ pub fn main() void {
const le = [_]u8{ 1, 3 };
const et = [_]u8{ 3, 7 };
- // I want this to contain digits: 1 3 3 7
+ // (Problem 1)
+ // Please set this array concatenating the two arrays above.
+ // It should result in: 1 3 3 7
const leet = ???;
- // I want this to contain digits: 1 0 0 1 1 0 0 1 1 0 0 1
+ // (Problem 2)
+ // Please set this array to using repetition.
+ // It should result in: 1 0 0 1 1 0 0 1 1 0 0 1
const bit_pattern = [_]u8{ ??? } ** 3;
-
+ // Okay, that's all of the problems. Let's see the results.
+ //
// We could print these arrays with leet[0], leet[1],...but let's
- // have a little preview of Zig 'for' loops instead!
+ // have a little preview of Zig "for" loops instead:
std.debug.print("LEET: ", .{});
for (leet) |*n| {