← 2a1d4a2b313a · 2a41d6b25262 →

2a40849f3961

On a zero-background maze with gray(5) walls and one checkpoint each of colors 1,2,3,4, find shortest 4-neighbor paths 1->2, 2->3, and 3->4 through non-wall cells. Resolve equal paths in up/down/left/right BFS order and paint only zero-valued interior route cells cyan(8).

Generated by the released generator before publication; every output was computed by its Racket reference rule. White outlines mark the cells the rule changed. Lesson check:

refuted: a demonstration contradicts the rival. survived_all: it fits every demonstration and also gives the intended answer, so it cannot mislead here. ambiguous: it fits every demonstration but answers the query differently. Names are as declared by the generator; a declared shortcut is not guaranteed to fit the original pairs (see the paper’s Limitations).

Original task pairs

From the source task; the reference rule must reproduce them.

Reference rule (Racket)

(rule!
  (let ((dummy 0))

    (define (same-pos? a b)
      (and (= (fst a) (fst b)) (= (snd a) (snd b))))
    (define (pos-in? p lst)
      (any? (lambda (q) (same-pos? p q)) lst))
    (define (parent-of p parents)
      (let ((hit (find-first (lambda (entry) (same-pos? p (first entry))) parents)))
        (if hit (second hit) #f)))
    (define (reconstruct goal parents)
      (let loop ((cur goal) (acc (list)))
        (let ((prev (parent-of cur parents)))
          (if prev
              (loop prev (cons cur acc))
              (cons cur acc)))))
    (define (shortest-path start goal)
      (let loop ((visited (list))
                 (queue (list start))
                 (parents (list (list start #f))))
        (if (empty? queue)
            (list)
            (let ((cur (first queue))
                  (restq (cdr queue)))
              (cond
                [(pos-in? cur visited) (loop visited restq parents)]
                [(same-pos? cur goal) (reconstruct goal parents)]
                [else
                 (let* ((new-visited (cons cur visited))
                        (r (fst cur))
                        (c (snd cur))
                        (neighbors
                          (filter
                            (lambda (n)
                              (let ((nr (fst n)) (nc (snd n)))
                                (and (in-bounds? nr nc h w)
                                     (not (= (cell-at g nr nc) 5))
                                     (not (pos-in? n new-visited))
                                     (not (pos-in? n restq)))))
                            (map
                              (lambda (d) (list (+ r (fst d)) (+ c (snd d))))
                              cardinal-deltas))))
                   (loop new-visited
                         (append restq neighbors)
                         (append parents (map (lambda (n) (list n cur)) neighbors))))])))))

    (define (interior path start goal)
      (filter
        (lambda (p) (not (or (same-pos? p start) (same-pos? p goal))))
        path))
    (let* ((p1 (first (find-color g 1)))
           (p2 (first (find-color g 2)))
           (p3 (first (find-color g 3)))
           (p4 (first (find-color g 4)))
           (segments (list (list p1 p2) (list p2 p3) (list p3 p4)))
           (path-cells
             (flatmap
               (lambda (seg)
                 (let* ((start (first seg))
                        (goal (second seg))
                        (path (shortest-path start goal)))
                   (if (empty? path) (list) (interior path start goal))))
               segments)))
      (grid-from-fn h w
        (lambda (r c)
          (let ((v (cell-at g r c)))
            (if (and (= v 0) (pos-in? (list r c) path-cells)) 8 v)))))))

Provenance

Generator
generators/2a40849f3961/generator.py
Notes and decisions
generators/2a40849f3961/notes.md
Review label
reviewed_safe
Generator SHA-256
a1d94459fe043258be0f7c8b7bdd4c54698c8ec08f18f433a61f02de59bdcae2
Rule hash
cd7f3a44d341
Sources
bank:f6c2fd26c5e5
Lesson seeds
20261108, 20261109, 20261110, 20261111, 20261112
Reproduce lesson 1
arcpuzzles generate 2a40849f3961 --count 1 --seed 20261108 --test 1