mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-21 21:53:11 -05:00
099-105 completed
This commit is contained in:
parent
e06cf45604
commit
8a6106f82b
7 changed files with 13 additions and 13 deletions
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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});
|
||||
|
|
Loading…
Reference in a new issue