From bdfe3df2947f8787c8a4ef8c534f6a8932e13871 Mon Sep 17 00:00:00 2001 From: Ibrahim Muftee Date: Mon, 29 Jun 2026 15:11:40 -0500 Subject: feat: begin solving exercises --- exercises/074_comptime9.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'exercises/074_comptime9.zig') diff --git a/exercises/074_comptime9.zig b/exercises/074_comptime9.zig index dfdc588..82bf6b3 100644 --- a/exercises/074_comptime9.zig +++ b/exercises/074_comptime9.zig @@ -28,12 +28,12 @@ fn makeCreature(comptime count: usize, comptime fmt: []const u8) [count]Animal { start, // Ready to start a new animal. l, // This means we've seen an "l", so if we see an "m", we know it's a Llama. }; - var state = State.start; + comptime var state = State.start; // We return an array of animals representing the creature. (This is why we // really needed the 'count' parameter. Arrays need a size.) var animals: [count]Animal = undefined; - var next_animal: usize = 0; + comptime var next_animal: usize = 0; inline for (fmt) |char| { @@ -57,7 +57,10 @@ fn makeCreature(comptime count: usize, comptime fmt: []const u8) [count]Animal { // // What do you think happens with Gators? Do they join with // other animals or is this an error? - 'g' => ???, + 'g' => { + animals[next_animal] = .Gator; + next_animal += 1; + }, else => @compileError(std.fmt.comptimePrint("No animal starts with '{c}'!", .{char})), }, @@ -69,7 +72,7 @@ fn makeCreature(comptime count: usize, comptime fmt: []const u8) [count]Animal { next_animal += 1; // Something is missing here. After we finish a Llama, we // need to be ready to _start_ over with a new animal... - ??? + state = State.start; }, else => @compileError("Only llamas start with 'l'!"), -- cgit v1.2.3