diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-03-12 18:59:46 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-03-12 18:59:46 -0500 |
commit | 6ad9774189fbd64b2f2c9519f4513ab34b0c3809 (patch) | |
tree | d6c90700131d5b28e898881f13e2a05612e4703f /exercises/005_arrays2.zig | |
parent | be36352572ddb18218e1830e49316c259dea5e8c (diff) | |
download | ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.tar.gz ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.tar.bz2 ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.tar.xz ziglings-6ad9774189fbd64b2f2c9519f4513ab34b0c3809.zip |
"999 is enough for anybody" triple-zero padding (#18)
When I hit 999 exercises, I will finally have reached the ultimate
state of soteriological release and no more exercises will be needed.
The cycle will be complete. All that will be left is perfect quietude,
freedom, and highest happiness.
Diffstat (limited to 'exercises/005_arrays2.zig')
-rw-r--r-- | exercises/005_arrays2.zig | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/exercises/005_arrays2.zig b/exercises/005_arrays2.zig new file mode 100644 index 0000000..9282a31 --- /dev/null +++ b/exercises/005_arrays2.zig @@ -0,0 +1,47 @@ +// +// 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 }; // equals 1 2 3 4 5 +// +// You can use '**' to repeat an array: +// +// const d = [_]u8{ 1,2,3 } ** 2; // equals 1 2 3 1 2 3 +// +const std = @import("std"); + +pub fn main() void { + const le = [_]u8{ 1, 3 }; + const et = [_]u8{ 3, 7 }; + + // (Problem 1) + // Please set this array concatenating the two arrays above. + // It should result in: 1 3 3 7 + const leet = ???; + + // (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: + std.debug.print("LEET: ", .{}); + + for (leet) |*n| { + std.debug.print("{}", .{n.*}); + } + + std.debug.print(", Bits: ", .{}); + + for (bit_pattern) |*n| { + std.debug.print("{}", .{n.*}); + } + + std.debug.print("\n", .{}); +} |