mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-11-09 19:40:48 -05:00
Added comptime wizardry to 075 quiz8
Thanks to Helios on Discord for the wizardry!
This commit is contained in:
parent
361630fdce
commit
c3128f3dee
1 changed files with 15 additions and 7 deletions
|
@ -154,13 +154,21 @@ pub fn main() void {
|
||||||
const start = &a; // Archer's Point
|
const start = &a; // Archer's Point
|
||||||
const destination = &f; // Fox Pond
|
const destination = &f; // Fox Pond
|
||||||
|
|
||||||
// TODO: can we neaten this up????
|
// We could either have this:
|
||||||
a.paths = a_paths[0..];
|
//
|
||||||
b.paths = b_paths[0..];
|
// a.paths = a_paths[0..];
|
||||||
c.paths = c_paths[0..];
|
// b.paths = b_paths[0..];
|
||||||
d.paths = d_paths[0..];
|
// c.paths = c_paths[0..];
|
||||||
e.paths = e_paths[0..];
|
// d.paths = d_paths[0..];
|
||||||
f.paths = f_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 notebook = HermitsNotebook{};
|
||||||
var working_note = NotebookEntry{
|
var working_note = NotebookEntry{
|
||||||
|
|
Loading…
Reference in a new issue