6 Commits

Author SHA1 Message Date
Chris Boesch 151db7bcd4 Merge pull request 'Remove prefilled solution' (#485) from it3x/remove-solution into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/485
2026-06-29 20:30:13 +02:00
it3x b39f223b8c Fix patch for 109_files 2026-06-29 17:14:05 +00:00
it3x e932615712 Remove prefilled solution
See #478
2026-06-29 17:09:23 +00:00
it3x 98b831aec4 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
2026-06-29 18:48:05 +02:00
Chris Boesch f69c79bcb6 Merge pull request 'added absolute path to exercises, also for tests' (#484) from root_path into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/484
2026-06-29 18:38:40 +02:00
Chris Boesch 951351aa2e added absolute path to exercises, also for tests 2026-06-29 18:30:49 +02:00
6 changed files with 43 additions and 15 deletions
+16 -2
View File
@@ -26,8 +26,13 @@ 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_unit = [_]u8{ ??? };
const bit_pattern: [3 * bit_pattern_unit.len]u8 = @bitCast(@as([3][bit_pattern_unit.len]u8, @splat(bit_pattern_unit)));
const bit_pattern_unit = ???;
// How long should the bit pattern be?
const len = ???;
// For now, don't worry about the use of SIMD.
const bit_pattern: [len]u8 = std.simd.repeat(len, bit_pattern_unit);
// Okay, that's all of the problems. Let's see the results.
//
@@ -53,3 +58,12 @@ pub fn main() void {
std.debug.print("\n", .{});
}
// For the curious:
//
// The `std.simd.repeat` function takes a target length and a pattern,
// and returns a vector filled with that pattern repeated to the
// desired length.
//
// For example, `repeat(5, [_]u8{1, 2})` will return a vector
// equivalent to `.{1, 2, 1, 2, 1}`.
+1 -1
View File
@@ -50,7 +50,7 @@ pub fn main(init: std.process.Init) !void {
// wait a minute...
// opening a directory might fail!
// what should we do here?
var output_dir: std.Io.Dir = try cwd.openDir(io, "output", .{});
var output_dir: std.Io.Dir = cwd.openDir(io, "output", .{});
defer output_dir.close(io);
// we try to open the file `zigling.txt`,
+4
View File
@@ -145,3 +145,7 @@ pub fn main() void {
print("Max difference (old fn): {d: >5.3}\n", .{mpd_old});
print("Max difference (new fn): {d: >5.3}\n", .{mpd_new});
}
// Another cool feature of Vectors is repeating patterns.
// Remember the arrays exercise from earlier where we created an array
// by repeating a pattern? See `005_arrays2.zig`.
+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);
+11 -2
View File
@@ -1,5 +1,5 @@
--- exercises/109_files.zig 2026-03-20 19:23:48.874150121 +0100
+++ answers/109_files.zig 2026-04-02 10:51:15.813831695 +0200
--- exercises/109_files.zig 2026-06-29 17:08:04.124224900 +0000
+++ answers/109_files.zig 2026-06-29 17:13:20.696220533 +0000
@@ -41,7 +41,7 @@
// by doing nothing
//
@@ -9,6 +9,15 @@
// if there's any other unexpected error we just propagate it through
else => return e,
};
@@ -50,7 +50,7 @@
// wait a minute...
// opening a directory might fail!
// what should we do here?
- var output_dir: std.Io.Dir = cwd.openDir(io, "output", .{});
+ var output_dir: std.Io.Dir = try cwd.openDir(io, "output", .{});
defer output_dir.close(io);
// we try to open the file `zigling.txt`,
@@ -61,7 +61,7 @@
// but here we are not yet done writing to the file
// if only there were a keyword in Zig that
+1 -4
View File
@@ -370,8 +370,7 @@ fn runTest(ctx: Context, ex: Exercise) !void {
const arena = ctx.arena;
print("Compiling {s}...\n", .{ex.main_file});
const path = std.fs.path.join(arena, &.{ ctx.work_path, ex.main_file }) catch
@panic("OOM");
const path = std.fs.path.join(arena, &.{ ctx.root_path, ctx.work_path, ex.main_file }) catch @panic("OOM");
var argv = std.ArrayList([]const u8).initCapacity(arena, 8) catch @panic("OOM");
argv.append(arena, ctx.zig_exe) catch @panic("OOM");
@@ -600,8 +599,6 @@ const exercises = [_]Exercise{
.main_file = "005_arrays2.zig",
.output = "LEET: 1337, Bits: 100110011001",
.hint = "Fill in the two arrays.",
.skip = true,
.skip_hint = "Better solution is needed.",
},
.{
.main_file = "006_strings.zig",