diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-05-04 17:30:31 +0200 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-05-04 17:30:31 +0200 |
| commit | dde51b3126b0f9cfbbf5d1ec49fd19ad37dd5a5f (patch) | |
| tree | a333fe8d515ae8fad19a94e37bdc4649f6dd662c /exercises/005_arrays2.zig | |
| parent | 1ba1e301a8a977f652157ca60a0522c95bc736aa (diff) | |
| parent | 8af3372cf204861f8541f91e47543f1b33337c5b (diff) | |
Merge pull request 'fixed removed array multiplication' (#423) from array_mult into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/423
Diffstat (limited to 'exercises/005_arrays2.zig')
| -rw-r--r-- | exercises/005_arrays2.zig | 13 |
1 files changed, 5 insertions, 8 deletions
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. // |
