From 8a6106f82bbb21ced713e4d19c4fc2c89d085796 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 21 Jun 2024 08:49:10 -0400 Subject: [PATCH] 099-105 completed --- exercises/099_formatting.zig | 2 +- exercises/100_for4.zig | 2 +- exercises/101_for5.zig | 2 +- exercises/102_testing.zig | 4 ++-- exercises/103_tokenization.zig | 8 ++++---- exercises/104_threading.zig | 4 ++-- exercises/105_threading2.zig | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/exercises/099_formatting.zig b/exercises/099_formatting.zig index 4b64209..6d505c2 100644 --- a/exercises/099_formatting.zig +++ b/exercises/099_formatting.zig @@ -131,7 +131,7 @@ pub fn main() !void { for (0..size) |b| { // What formatting is needed here to make our columns // nice and straight? - print("{???} ", .{(a + 1) * (b + 1)}); + print("{d:>3} ", .{(a + 1) * (b + 1)}); } // After each row we use double line feed: diff --git a/exercises/100_for4.zig b/exercises/100_for4.zig index e0fa602..13ff1b2 100644 --- a/exercises/100_for4.zig +++ b/exercises/100_for4.zig @@ -39,7 +39,7 @@ pub fn main() void { const hex_nums = [_]u8{ 0xb, 0x2a, 0x77 }; const dec_nums = [_]u8{ 11, 42, 119 }; - for (hex_nums, ???) |hn, ???| { + for (hex_nums, dec_nums) |hn, dn| { if (hn != dn) { std.debug.print("Uh oh! Found a mismatch: {d} vs {d}\n", .{ hn, dn }); return; diff --git a/exercises/101_for5.zig b/exercises/101_for5.zig index 200e71d..be968db 100644 --- a/exercises/101_for5.zig +++ b/exercises/101_for5.zig @@ -51,7 +51,7 @@ pub fn main() void { // We would like to number our list starting with 1, not 0. // How do we do that? - for (roles, gold, experience, ???) |c, g, e, i| { + for (roles, gold, experience, 1..) |c, g, e, i| { const role_name = switch (c) { .wizard => "Wizard", .thief => "Thief", diff --git a/exercises/102_testing.zig b/exercises/102_testing.zig index 89a0ee8..150de34 100644 --- a/exercises/102_testing.zig +++ b/exercises/102_testing.zig @@ -83,7 +83,7 @@ fn sub(a: f16, b: f16) f16 { // an error that you need // to correct. test "sub" { - try testing.expect(sub(10, 5) == 6); + try testing.expect(sub(10, 5) == 5); try testing.expect(sub(3, 1.5) == 1.5); } @@ -108,5 +108,5 @@ test "divide" { // Now we test if the function returns an error // if we pass a zero as denominator. // But which error needs to be tested? - try testing.expectError(error.???, divide(15, 0)); + try testing.expectError(error.DivisionByZero, divide(15, 0)); } diff --git a/exercises/103_tokenization.zig b/exercises/103_tokenization.zig index eded880..eea92ff 100644 --- a/exercises/103_tokenization.zig +++ b/exercises/103_tokenization.zig @@ -119,9 +119,9 @@ // after all we need some practice. Suppose we want to count the words // of this little poem: // -// My name is Ozymandias, King of Kings; -// Look on my Works, ye Mighty, and despair! -// by Percy Bysshe Shelley +// My name is Ozymandias, King of Kings; +// Look on my Works, ye Mighty, and despair! +// by Percy Bysshe Shelley // // const std = @import("std"); @@ -136,7 +136,7 @@ pub fn main() !void { ; // now the tokenizer, but what do we need here? - var it = std.mem.tokenizeAny(u8, poem, ???); + var it = std.mem.tokenizeAny(u8, poem, " ,;!\n"); // print all words and count them var cnt: usize = 0; diff --git a/exercises/104_threading.zig b/exercises/104_threading.zig index 9c4e216..a99ac33 100644 --- a/exercises/104_threading.zig +++ b/exercises/104_threading.zig @@ -97,12 +97,12 @@ pub fn main() !void { defer handle.join(); // Second thread - const handle2 = try std.Thread.spawn(.{}, thread_function, .{-4}); // that can't be right? + const handle2 = try std.Thread.spawn(.{}, thread_function, .{2}); // that can't be right? defer handle2.join(); // Third thread const handle3 = try std.Thread.spawn(.{}, thread_function, .{3}); - defer ??? // <-- something is missing + defer handle3.join(); // <-- something is missing // After the threads have been started, // they run in parallel and we can still do some work in between. diff --git a/exercises/105_threading2.zig b/exercises/105_threading2.zig index 7ca8f5c..6e29783 100644 --- a/exercises/105_threading2.zig +++ b/exercises/105_threading2.zig @@ -81,8 +81,8 @@ pub fn main() !void { defer handle1.join(); // Second thread to calculate the minus numbers. - ??? - + const handle2 = try std.Thread.spawn(.{}, thread_pi, .{ &pi_minus, 3, count }); + defer handle2.join(); } // Here we add up the results. std.debug.print("PI ≈ {d:.8}\n", .{4 + pi_plus - pi_minus});