diff options
| author | Dave Gauer <[email protected]> | 2022-03-19 20:00:10 -0400 |
|---|---|---|
| committer | Dave Gauer <[email protected]> | 2022-03-19 20:00:10 -0400 |
| commit | c3128f3deeef0359c267d5084b89566a9233df17 (patch) | |
| tree | 2e7b58482309d7ae5a06cca165306c4fec5195ad | |
| parent | 361630fdce8a3b4868590c2b2e96625455fa4485 (diff) | |
| download | ziglings-c3128f3deeef0359c267d5084b89566a9233df17.tar.xz ziglings-c3128f3deeef0359c267d5084b89566a9233df17.zip | |
Added comptime wizardry to 075 quiz8
Thanks to Helios on Discord for the wizardry!
| -rw-r--r-- | exercises/075_quiz8.zig | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/exercises/075_quiz8.zig b/exercises/075_quiz8.zig index 1e026a4..e05830e 100644 --- a/exercises/075_quiz8.zig +++ b/exercises/075_quiz8.zig @@ -154,13 +154,21 @@ pub fn main() void { const start = &a; // Archer's Point const destination = &f; // Fox Pond - // TODO: can we neaten this up???? - a.paths = a_paths[0..]; - b.paths = b_paths[0..]; - c.paths = c_paths[0..]; - d.paths = d_paths[0..]; - e.paths = e_paths[0..]; - f.paths = f_paths[0..]; + // We could either have this: + // + // a.paths = a_paths[0..]; + // b.paths = b_paths[0..]; + // c.paths = c_paths[0..]; + // d.paths = d_paths[0..]; + // e.paths = e_paths[0..]; + // f.paths = f_paths[0..]; + // + // or this comptime wizardry: + // + const letters = [_][]const u8{ "a", "b", "c", "d", "e", "f" }; + inline for (letters) |letter| { + @field(@This(), letter).paths = @field(@This(), letter ++ "_paths")[0..]; + } var notebook = HermitsNotebook{}; var working_note = NotebookEntry{ |
