Refresh 005_arrays2 exercise

Updated the exercise to use SIMD. This allows us to
cross-reference the concept from 112_vectors back to 005_arrays2,
introducing a handy feature of vectors early on.

See #430
This commit is contained in:
it3x
2026-06-27 09:04:32 +00:00
committed by Chris Boesch
parent f69c79bcb6
commit 98b831aec4
4 changed files with 30 additions and 10 deletions
+10 -6
View File
@@ -1,6 +1,6 @@
--- exercises/005_arrays2.zig 2026-05-04 16:26:32.778330847 +0200
+++ answers/005_arrays2.zig 2026-05-04 16:26:13.082917974 +0200
@@ -21,12 +21,12 @@
--- exercises/005_arrays2.zig 2026-06-27 09:03:29.918124920 +0000
+++ answers/005_arrays2.zig 2026-06-27 09:01:13.162138431 +0000
@@ -21,15 +21,15 @@
// (Problem 1)
// Please set this array concatenating the two arrays above.
// It should result in: 1 3 3 7
@@ -10,8 +10,12 @@
// (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_unit = [_]u8{ ??? };
- const bit_pattern_unit = ???;
+ const bit_pattern_unit = [_]u8{ 1, 0, 0, 1 };
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.
// How long should the bit pattern be?
- const len = ???;
+ const len = 3 * bit_pattern_unit.len;
// For now, don't worry about the use of SIMD.
const bit_pattern: [len]u8 = std.simd.repeat(len, bit_pattern_unit);