From 8af3372cf204861f8541f91e47543f1b33337c5b Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Mon, 4 May 2026 17:15:30 +0200 Subject: fixed removed array multiplication --- exercises/005_arrays2.zig | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'exercises/005_arrays2.zig') diff --git a/exercises/005_arrays2.zig b/exercises/005_arrays2.zig index 497d400..fdbb505 100644 --- a/exercises/005_arrays2.zig +++ b/exercises/005_arrays2.zig @@ -1,5 +1,5 @@ // -// Zig has some fun array operators. +// Zig has one array operators. // // You can use '++' to concatenate two arrays: // @@ -7,12 +7,8 @@ // 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 -// -// Note that both '++' and '**' only operate on arrays while your -// program is _being compiled_. This special time is known in Zig +// Note that '++'' only operate on arrays while your program is +// _being compiled_. This special time is known in Zig // parlance as "comptime" and we'll learn plenty more about that // later. // @@ -30,7 +26,8 @@ pub fn main() void { // (Problem 2) // Please set this array using repetition. // It should result in: 1 0 0 1 1 0 0 1 1 0 0 1 - const bit_pattern = [_]u8{ ??? } ** 3; + const bit_pattern_unit = [_]u8{ ??? }; + const bit_pattern: [3 * bit_pattern_unit.len]u8 = @bitCast(@as([3][bit_pattern_unit.len]u8, @splat(bit_pattern_unit))); // Okay, that's all of the problems. Let's see the results. // -- cgit v1.2.3