056-058 completed

This commit is contained in:
Andrew Scott 2024-05-05 08:54:47 -04:00
parent 30d90e0019
commit 7108f89eb3
Signed by: a
GPG key ID: 7CD5A5977E4931C1
3 changed files with 6 additions and 5 deletions

View file

@ -1,2 +1,3 @@
# Ziglings # Ziglings
# ⚠️ My solutions, not the [original exercises](https://codeberg.org/ziglings/exercises) # ⚠️ My solutions, not the [original exercises](https://codeberg.org/ziglings/exercises)

View file

@ -15,7 +15,7 @@
// //
const std = @import("std"); const std = @import("std");
const Insect = union(InsectStat) { const Insect = union(enum) {
flowers_visited: u16, flowers_visited: u16,
still_alive: bool, still_alive: bool,
}; };

View file

@ -192,8 +192,8 @@ const TripItem = union(enum) {
// Oops! The hermit forgot how to capture the union values // Oops! The hermit forgot how to capture the union values
// in a switch statement. Please capture both values as // in a switch statement. Please capture both values as
// 'p' so the print statements work! // 'p' so the print statements work!
.place => print("{s}", .{p.name}), .place => |p| print("{s}", .{p.name}),
.path => print("--{}->", .{p.dist}), .path => |p| print("--{}->", .{p.dist}),
} }
} }
}; };
@ -255,7 +255,7 @@ const HermitsNotebook = struct {
// dereference and optional value "unwrapping" look // dereference and optional value "unwrapping" look
// together. Remember that you return the address with the // together. Remember that you return the address with the
// "&" operator. // "&" operator.
if (place == entry.*.?.place) return entry; if (place == entry.*.?.place) return &entry.*.?;
// Try to make your answer this long:__________; // Try to make your answer this long:__________;
} }
return null; return null;
@ -309,7 +309,7 @@ const HermitsNotebook = struct {
// //
// Looks like the hermit forgot something in the return value of // Looks like the hermit forgot something in the return value of
// this function. What could that be? // this function. What could that be?
fn getTripTo(self: *HermitsNotebook, trip: []?TripItem, dest: *Place) void { fn getTripTo(self: *HermitsNotebook, trip: []?TripItem, dest: *Place) TripError!void {
// We start at the destination entry. // We start at the destination entry.
const destination_entry = self.getEntry(dest); const destination_entry = self.getEntry(dest);