|
10 | 10 |
|
11 | 11 | ## 1. Drain the tide queue |
12 | 12 |
|
13 | | -- Start with `<dlist>`, `[ push-back ] each` to fill it, then a |
14 | | - `while` loop that pops the front until the deque is empty, |
15 | | - accumulating into a `V{ } clone` and converting to an array |
16 | | - at the end with `>array`. |
| 13 | +- Start with `<dlist>`, `[ push-back ] each` to fill it, then |
| 14 | + drain it with an `until` loop (`[ deque-empty? ]` predicate): |
| 15 | + pop the front into a `V{ } clone`, converting to an array at |
| 16 | + the end with `>array`. |
17 | 17 |
|
18 | 18 | ## 2. Coves reachable |
19 | 19 |
|
20 | 20 | - Pattern: `HS{ } clone` for `visited`, `<dlist>` for |
21 | 21 | `frontier`, mark `start` visited and push it onto the |
22 | | - frontier, then loop while the frontier isn't empty: pop the |
| 22 | + frontier, then loop until the frontier is empty: pop the |
23 | 23 | front, look up its neighbours in the chart with `at`, and for |
24 | 24 | each unseen neighbour adjoin to `visited` and push-back onto |
25 | 25 | the frontier. |
|
29 | 29 | - Same shape as task 2, but the deque carries `{ cove distance }` |
30 | 30 | pairs. When you pop a pair whose cove equals the goal, record |
31 | 31 | the distance as the answer and stop. Use a mutable local |
32 | | - (`f :> answer!`) and gate the loop on |
33 | | - `frontier deque-empty? not answer not and`. |
| 32 | + (`f :> answer!`) and gate the `until` loop on |
| 33 | + `frontier deque-empty? answer or`. |
34 | 34 |
|
35 | 35 | ## 4. Gold count |
36 | 36 |
|
|
0 commit comments