diff options
| author | Orfeas <38209077+0xfea5@users.noreply.github.com> | 2023-12-08 20:00:01 +0200 |
|---|---|---|
| committer | Orfeas <38209077+0xfea5@users.noreply.github.com> | 2025-10-28 23:20:45 +0200 |
| commit | 73023daf785347bc2417f898c6633de28e9efc6a (patch) | |
| tree | 2c7bb2b0a319dc6307e1d20b61434bc20ea6c641 | |
| parent | day7: moving cmp function in struct (diff) | |
| download | aoc23-73023daf785347bc2417f898c6633de28e9efc6a.tar.gz aoc23-73023daf785347bc2417f898c6633de28e9efc6a.zip | |
day8: use tokenizeAny instead of splitAny
thanks sigod
| -rw-r--r-- | day08/solution.zig | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/day08/solution.zig b/day08/solution.zig index 75e6e73..ae2a392 100644 --- a/day08/solution.zig +++ b/day08/solution.zig | |||
| @@ -24,24 +24,12 @@ const Rule = struct { | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | pub fn init(text: []const u8) Rule { | 26 | pub fn init(text: []const u8) Rule { |
| 27 | var splitTokens = mem.splitAny(u8, text, " =(),"); | 27 | var splitTokens = mem.tokenizeAny(u8, text, " =(),"); |
| 28 | var nonEmpty = [3]u32{ undefined, undefined, undefined }; | ||
| 29 | var i: usize = 0; | ||
| 30 | |||
| 31 | while (splitTokens.next()) |tok| { | ||
| 32 | if (tok.len != 3) { | ||
| 33 | continue; | ||
| 34 | } | ||
| 35 | nonEmpty[i] = hash(tok); | ||
| 36 | i += 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | assert(i == 3); | ||
| 40 | 28 | ||
| 41 | return Rule{ | 29 | return Rule{ |
| 42 | .key = nonEmpty[0], | 30 | .key = hash(splitTokens.next().?), |
| 43 | .left = nonEmpty[1], | 31 | .left = hash(splitTokens.next().?), |
| 44 | .right = nonEmpty[2], | 32 | .right = hash(splitTokens.next().?), |
| 45 | }; | 33 | }; |
| 46 | } | 34 | } |
| 47 | }; | 35 | }; |
