Add solutions

This commit is contained in:
Laurens Miers 2024-09-25 15:26:17 +02:00
parent 7417f01d5d
commit b056b6ad81
96 changed files with 229 additions and 166 deletions

View file

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