← public_eval_4c416de3 · public_eval_4e34c42c →
public_eval_4c7dc4dd
No summary in the catalog.
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!
;; Decode four square panels and their two enclosing groups from a noisy
;; canvas. The complete pair teaches a relation: routed endpoint completion,
;; reflection closure, sparse-key/palette transfer, or periodic mask inversion.
;; Recover the relation and its palette/orientation from the reference pair,
;; then apply it to the nonempty panel paired with the unique blank panel.
;; Conflicting supported interpretations fail rather than silently guessing.
(lambda (g)
(let ()
(define changes-only #f)
(define (border? r c rr cc)
(let ((v (at g r c)))
(and (not (= v 0))
(for/and ((x (range c (+ cc 1)))) (and (= (at g r x) v) (= (at g rr x) v)))
(for/and ((y (range r (+ rr 1)))) (and (= (at g y c) v) (= (at g y cc) v))))))
(define (frames-at size)
(for*/list ((r (range (+ (- h size) 1))) (c (range (+ (- w size) 1)))
#:when (and (border? r c (+ r size -1) (+ c size -1))
(for*/or ((y (range (+ r 1) (+ r size -1))) (x (range (+ c 1) (+ c size -1)))) (= (at g y x) 0))))
(list r c (+ r size -1) (+ c size -1) (subgrid g (+ r 1) (+ c 1) (+ r size -2) (+ c size -2)))))
(define sizes (filter (lambda (s) (= (length (frames-at s)) 4)) (reverse (range 5 (+ (min h w) 1)))))
(define frames (if (null? sizes) (error 'analogy "four equal square frames required") (frames-at (first sizes))))
(define n (rows (fifth (first frames))))
(define (cells p) (for*/list ((r (range n)) (c (range n)) #:when (not (= (at p r c) 0))) (list r c)))
(define blanks (filter (lambda (i) (null? (cells (fifth (list-ref frames i))))) (range 4)))
(define blank (if (= (length blanks) 1) (first blanks) (error 'analogy "exactly one blank required")))
(define bf (list-ref frames blank))
(define choices
(apply append
(for/list ((mate (range 4)) #:unless (= mate blank))
(let* ((mf (list-ref frames mate)) (rlo (min (first bf) (first mf))) (clo (min (second bf) (second mf)))
(rhi (max (third bf) (third mf))) (chi (max (fourth bf) (fourth mf))))
(for*/list ((r (range rlo)) (c (range clo)) (rr (range (+ rhi 1) h)) (cc (range (+ chi 1) w))
#:when (and (border? r c rr cc)
(for/and ((i (range 4)) #:unless (or (= i blank) (= i mate)))
(let ((f (list-ref frames i))) (not (and (< r (first f)) (< c (second f)) (< (third f) rr) (< (fourth f) cc)))))))
(list (* (+ (- rr r) 1) (+ (- cc c) 1)) mate))))))
(define mate (if (null? choices) (error 'analogy "outer group missing")
(second (first (sort choices (lambda (a b) (< (first a) (first b))))))))
(define refs (for/list ((i (range 4)) #:unless (or (= i blank) (= i mate))) (fifth (list-ref frames i))))
(define query (fifth (list-ref frames mate)))
(define (route p)
(let* ((ns (cells p))
(between? (lambda (a b t)
(or (and (and (= (first a) (first b)) (= (first b) (first t))) (and (< (min (second a) (second b)) (second t)) (< (second t) (max (second a) (second b)))))
(and (and (= (second a) (second b)) (= (second b) (second t))) (and (< (min (first a) (first b)) (first t)) (< (first t) (max (first a) (first b))))))))
(edges (for*/list ((i (range (length ns))) (j (range (+ i 1) (length ns)))
#:when (let ((a (list-ref ns i)) (b (list-ref ns j)))
(and (or (= (first a) (first b)) (= (second a) (second b)))
(not (ormap (lambda (t) (between? a b t)) ns)))))
(list (list-ref ns i) (list-ref ns j))))
(degree (lambda (pt) (length (filter (lambda (e) (member pt e)) edges))))
(ends (filter (lambda (pt) (= (degree pt) 1)) ns)))
(if (not (and (>= (length ns) 3) (= (length ends) 2) (= (length edges) (- (length ns) 1))
(andmap (lambda (pt) (member (degree pt) '(1 2))) ns))) #f
(let* ((color (at p (first (first ends)) (second (first ends))))
(valid (and (= color (at p (first (second ends)) (second (second ends))))
(andmap (lambda (pt) (or (member pt ends) (not (= color (at p (first pt) (second pt)))))) ns))))
(if (not valid) #f
(for/fold ((out p)) ((edge edges))
(let ((a (first edge)) (b (second edge)))
(for*/fold ((out out)) ((r (range (min (first a) (first b)) (+ (max (first a) (first b)) 1)))
(c (range (min (second a) (second b)) (+ (max (second a) (second b)) 1))))
(if (= (at out r c) 0) (set-cell out r c color) out)))))))))
(define (reflect p)
(define (values-at r c)
(remove-duplicates (filter (lambda (v) (not (= v 0)))
(for*/list ((y (list r (- n r 1))) (x (list c (- n c 1)))) (at p y x)))))
(if (for*/and ((r (range n)) (c (range n))) (<= (length (values-at r c)) 1))
(grid-from-fn n n (lambda (r c) (let ((vs (values-at r c))) (if (null? vs) 0 (first vs))))) #f))
(define (turn p) (grid-from-fn n n (lambda (r c) (at p (- n c 1) r))))
(define (flip p) (grid-from-fn n n (lambda (r c) (at p r (- n c 1)))))
(define (transforms p)
(let* ((a (turn p)) (b (turn a)) (c (turn b)) (d (flip p)) (e (turn d)) (f (turn e)) (i (turn f)))
(list p a b c d e f i)))
(define (transfer src dst)
(if (>= (length (cells src)) (length (cells dst))) '()
(filter (lambda (x) x)
(for/list ((a (transforms src)) (b (transforms dst)))
(let* ((pairs (remove-duplicates (for*/list ((r (range n)) (c (range n))) (list (at a r c) (at query r c)))))
(keys (map first pairs)) (vals (map second pairs)))
(if (and (= (length keys) (length (remove-duplicates keys)))
(= (length vals) (length (remove-duplicates vals)))
(andmap (lambda (p) (equal? (= (first p) 0) (= (second p) 0))) pairs)
(for*/and ((r (range n)) (c (range n))) (assoc (at b r c) pairs)))
(list 'transfer (grid-from-fn n n (lambda (r c) (second (assoc (at b r c) pairs))))) #f))))))
(define (inverse a b)
(if (not (for*/and ((r (range n)) (c (range n))) (not (equal? (= (at a r c) 0) (= (at b r c) 0))))) #f
(let* ((texture (grid-from-fn n n (lambda (r c) (if (= (at a r c) 0) (at b r c) (at a r c)))))
(periodic (ormap (lambda (period)
(for*/and ((r (range n)) (c (range n)))
(= (at texture r c) (at texture (modulo r (first period)) (modulo c (second period))))))
'((1 1) (1 2) (2 1) (2 2))))
(pairs (remove-duplicates (for*/list ((r (range n)) (c (range n)) #:when (not (= (at query r c) 0)))
(list (at texture r c) (at query r c)))))
(keys (map first pairs)) (vals (map second pairs)))
(if (and periodic (= (length keys) (length (remove-duplicates keys)))
(= (length vals) (length (remove-duplicates vals)))
(for*/and ((r (range n)) (c (range n))) (assoc (at texture r c) pairs)))
(list 'complement (grid-from-fn n n (lambda (r c) (if (= (at query r c) 0) (second (assoc (at texture r c) pairs)) 0)))) #f))))
(define candidates
(append
(filter (lambda (x) x)
(for*/list ((order (list refs (reverse refs))) (op (list route reflect)))
(let ((a (first order)) (b (second order)))
(if (and (not (equal? a b)) (equal? (op a) b) (op query)) (list 'completion (op query)) #f))))
(transfer (first refs) (second refs)) (transfer (second refs) (first refs))
(let ((answer (inverse (first refs) (second refs)))) (if answer (list answer) '()))))
(define completed (if (null? candidates) (error 'analogy "no supported relation") (second (first candidates))))
(if (not (andmap (lambda (entry) (equal? (second entry) completed)) candidates))
(error 'analogy "ambiguous reference relation")
(if changes-only (grid-from-fn n n (lambda (r c) (if (= (at completed r c) (at query r c)) 0 (at completed r c)))) completed)))))
Provenance
- Generator
- generators/public_eval_4c7dc4dd/generator.py
- Notes and decisions
- generators/public_eval_4c7dc4dd/notes.md
- Review label
- reviewed_safe
- Generator SHA-256
- ae86097e70075e926be6e321c4821ea4db0135b39632ea1715d72054a148a22e
- Rule hash
- 3a82d8acc5ca
- Sources
- evaluation, public_eval:4c7dc4dd
- Lesson seeds
- 20261108, 20261109, 20261110, 20261111, 20261112
- Reproduce lesson 1
arcpuzzles generate public_eval_4c7dc4dd --count 1 --seed 20261108 --test 1