← public_eval_a251c730 · public_eval_a32d8b75 →

public_eval_a25697e4

Fit two-color keys into edge sockets; proper rotations preserve colors and reflected fits exchange the two colors.

parametric family

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* ((swap-reflections #t)
        (h (rows g)) (w (cols g)) (bg (mode g -1))
        (edge (lambda (cells)
                (cond ((ormap (lambda (p) (= (first p) 0)) cells) 0)
                      ((ormap (lambda (p) (= (second p) (- w 1))) cells) 1)
                      ((ormap (lambda (p) (= (first p) (- h 1))) cells) 2)
                      ((ormap (lambda (p) (= (second p) 0)) cells) 3)
                      (else -1))))
        (anchored (filter (lambda (o) (>= (edge (obj-cells o)) 0)) (objects g bg)))
        (anchor-cells (apply append (map obj-cells anchored)))
        (socket-keys (sort (remove-duplicates
                           (map (lambda (o) (list (edge (obj-cells o)) (obj-color o))) anchored)) cell<))
        (sockets
         (map (lambda (key)
                (let* ((cells (apply append
                              (map obj-cells
                               (filter (lambda (o) (and (= (edge (obj-cells o)) (first key))
                                                        (= (obj-color o) (second key)))) anchored))))
                       (box (bbox-of-cells cells)))
                  (filter (lambda (p) (= (at g (first p) (second p)) bg))
                    (for*/list ((r (in-range (first box) (+ 1 (third box))))
                                (c (in-range (second box) (+ 1 (fourth box))))) (list r c)))))
              socket-keys))
        (free-mask (grid-from-fn h w
                     (lambda (r c) (if (and (not (= (at g r c) bg))
                                           (not (member? (list r c) anchor-cells))) 1 0))))
        (pieces (map obj-cells (objects free-mask 0)))
        (source-cells (apply append pieces))
        (matrices '((1 0 0 1) (0 1 -1 0) (-1 0 0 -1) (0 -1 1 0)
                    (1 0 0 -1) (0 -1 -1 0) (-1 0 0 1) (0 1 1 0)))
        (transform (lambda (p m)
                     (list (+ (* (first m) (first p)) (* (second m) (second p)))
                           (+ (* (third m) (first p)) (* (fourth m) (second p))))))
        (normal (lambda (cells) (sort (normalize-cells cells) cell<)))
        (choices
         (map (lambda (cells)
                (let ((colors (sort (remove-duplicates (map (lambda (p) (at g (first p) (second p))) cells)) <)))
                  (filter (lambda (p) p)
                   (for*/list ((si (in-range (length sockets))) (color (in-list colors)) (mi (in-range 8)))
                     (let* ((hole (list-ref sockets si)) (matrix (list-ref matrices mi))
                            (part (filter (lambda (p) (= (at g (first p) (second p)) color)) cells))
                            (changed (map (lambda (p) (transform p matrix)) part)))
                       (if (and (not (empty? hole)) (equal? (normal changed) (normal hole)))
                           (let* ((dr (- (apply min (map first hole)) (apply min (map first changed))))
                                  (dc (- (apply min (map second hole)) (apply min (map second changed))))
                                  (painted (map (lambda (p)
                                                  (let ((q (transform p matrix)))
                                                    (list (+ dr (first q)) (+ dc (second q))
                                                          (at g (first p) (second p))))) cells)))
                             (if (andmap (lambda (p)
                                           (and (in-bounds? (first p) (second p) h w)
                                                (not (member? (list (first p) (second p)) anchor-cells)))) painted)
                                 (list si (>= mi 4) color colors painted mi) #f))
                           #f)))))) pieces))
        (cleared (grid-from-fn h w (lambda (r c)
                     (if (member? (list r c) source-cells) bg (at g r c))))))
   (letrec ((search
             (lambda (remaining used occupied)
               (if (empty? remaining) '()
                   (for/fold ((found #f)) ((candidate (in-list (first remaining))))
                     (if found found
                         (let ((destinations (map (lambda (p) (list (first p) (second p))) (fifth candidate))))
                           (if (or (member? (first candidate) used)
                                   (ormap (lambda (p) (member? p occupied)) destinations))
                               #f
                               (let ((tail (search (rest remaining) (cons (first candidate) used)
                                                   (append destinations occupied))))
                                 (if tail (cons candidate tail) #f))))))))))
     (let* ((placements (search choices '() '())))
       (for/fold ((out cleared)) ((placement (in-list placements)))
         (let ((colors (fourth placement))
               (swap? (and swap-reflections (second placement))))
           (for/fold ((next out)) ((p (in-list (fifth placement))))
             (set-cell next (first p) (second p)
                       (if swap? (if (= (third p) (first colors)) (second colors) (first colors))
                           (third p))))))))))

Provenance

Generator
generators/public_eval_a25697e4/generator.py
Notes and decisions
generators/public_eval_a25697e4/notes.md
Review label
reviewed_safe
Generator SHA-256
6836ed2f72b0f1b7b02a301fc9bf77f02e67f425c6ad97d88111c91d1892695c
Rule hash
3baf4daa1663
Sources
evaluation, public_eval:a25697e4
Lesson seeds
20261108, 20261109, 20261110, 20261111, 20261112
Reproduce lesson 1
arcpuzzles generate public_eval_a25697e4 --count 1 --seed 20261108 --test 1