← public_eval_409aa875 · public_eval_45a5af55 →

public_eval_446ef5d2

Reassemble a color-seam jigsaw at its L-marked corner.

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!
 ;; Translate disconnected fragments into a rectangle, keeping the L-marked
 ;; corner fixed. Every fragment joins the assembly along a completely matching
 ;; colored contact; other contacts may cross a color boundary. The rectangle's
 ;; outside edge has the marked corner's color. Remove the three-cell L marker.
 ;; In largest_region mode, assemble first, then recolor all maximum-area
 ;; same-color regions other than the background/border to the marker color.
 (lambda (g)
  (let ()
   (define mode "assembly")
   (define colors (range 10))
   (define (color-cells color)
     (for*/list ((r (range h)) (c (range w)) #:when (= (at g r c) color)) (list r c color)))
   (define bg (pick-max colors (lambda (color) (length (color-cells color)))))
   (define marker-info
     (for/or ((color colors) #:when (and (not (= color bg)) (= (length (color-cells color)) 3)))
       (define pts (map (lambda (p) (take p 2)) (color-cells color)))
       (define r0 (apply min (map first pts)))
       (define c0 (apply min (map second pts)))
       (define square (for*/list ((r (range r0 (+ r0 2))) (c (range c0 (+ c0 2)))) (list r c)))
       (define missing (filter (lambda (p) (not (member p pts))) square))
       (and (= (length missing) 1)
            (let ((p (first missing)))
              (and (in-bounds? (first p) (second p) h w)
                   (not (member (at g (first p) (second p)) (list bg color)))
                   (list color p (= (first p) (+ r0 1)) (= (second p) (+ c0 1))))))))
   (define marker (first marker-info))
   (define corner (second marker-info))
   (define base (at g (first corner) (second corner)))
   (define cleared (recolor g marker bg))
   ;; A binary mask gives four-connected multicolor fragments, rather than the
   ;; eight-connected objects-multicolor helper.
   (define mask (map-grid cleared (lambda (r c v) (if (= v bg) 0 1))))
   (define pieces
     (for/list ((o (objects mask 0)) (id (range (length (objects mask 0)))))
       (list id (for/list ((p (obj-cells o))) (list (first p) (second p) (at g (first p) (second p)))))))
   (define (cells p) (second p))
   (define (xy p) (take p 2))
   (define (adjacent? p q)
     (= (+ (abs (- (first p) (first q))) (abs (- (second p) (second q)))) 1))
   (define anchor (first (filter (lambda (p) (member corner (map xy (cells p)))) pieces)))
   (define area (apply + (map (lambda (p) (length (cells p))) pieces)))
   (define (shift p dr dc)
     (list (first p) (for/list ((v (cells p))) (list (+ (first v) dr) (+ (second v) dc) (third v)))))
   (define (colored p) (filter (lambda (v) (not (= (third v) base))) (cells p)))
   (define (cell-hash triples)
     (define table (make-hash))
     (for ((p triples)) (hash-set! table (xy p) (third p)))
     table)
   (define (match? a b)
     (define table (cell-hash (cells b)))
     (define contacts
       (for*/list ((p (cells a)) (d '((1 0) (-1 0) (0 1) (0 -1)))
                    #:do ((define q (list (+ (first p) (first d)) (+ (second p) (second d)))))
                    #:when (hash-has-key? table q))
         (list (third p) (hash-ref table q))))
     (and (not (null? contacts))
          (andmap (lambda (pair) (= (first pair) (second pair))) contacts)
          (ormap (lambda (pair) (not (= (first pair) base))) contacts)))
   (define (deltas a b)
     (remove-duplicates
       (for*/list ((p (colored a)) (q (colored b))
                   (d '((1 0) (-1 0) (0 1) (0 -1)))
                   #:when (= (third p) (third q)))
         (list (- (+ (first q) (first d)) (first p))
               (- (+ (second q) (second d)) (second p))))))
   ;; Pairwise compatible shifts depend only on source shapes, not search
   ;; order. Cache them once; recomputing all cell cross-products at every node
   ;; exceeds the protected runtime budget on the retained 30x30 regression.
   (define link-cache (make-hash))
   (define (links a b)
     (define key (list (first a) (first b)))
     (unless (hash-has-key? link-cache key)
       (define table (cell-hash (cells b)))
       (hash-set! link-cache key
         (filter (lambda (delta)
                   (define moved (shift a (first delta) (second delta)))
                   (and (not (ormap (lambda (p) (hash-has-key? table (xy p))) (cells moved)))
                        (match? moved b)))
                 (deltas a b))))
     (hash-ref link-cache key))
   (define solution
     (for/or ((H (range 2 (+ h 1))) #:when (zero? (remainder area H)))
       (define W (quotient area H))
       (define r0 (if (third marker-info) (first corner) (- (+ (first corner) 1) H)))
       (define c0 (if (fourth marker-info) (second corner) (- (+ (second corner) 1) W)))
       (define visited (make-hash))
       (define (inside? p)
         (for/and ((v (cells p)))
           (and (<= r0 (first v) (- (+ r0 H) 1))
                (<= c0 (second v) (- (+ c0 W) 1))
                (or (and (not (member (first v) (list r0 (- (+ r0 H) 1))))
                         (not (member (second v) (list c0 (- (+ c0 W) 1)))))
                    (= (third v) base)))))
       (define (search placed pending)
         (define state (sort placed < #:key first))
         (cond
           ((null? pending) placed)
           ((hash-has-key? visited state) #f)
           (else
            (hash-set! visited state #t)
            (define occupied (cell-hash (append-map cells placed)))
            (for/or ((p pending))
              (for/or ((q placed))
                (define original-q (list-ref pieces (first q)))
                (define qr (- (first (first (cells q))) (first (first (cells original-q)))))
                (define qc (- (second (first (cells q))) (second (first (cells original-q)))))
                (for/or ((delta (links p original-q)))
                  (define moved (shift p (+ qr (first delta)) (+ qc (second delta))))
                  (and (inside? moved)
                       (not (ormap (lambda (v) (hash-has-key? occupied (xy v))) (cells moved)))
                       (search (cons moved placed) (remove p pending)))))))))
       (and (<= 2 W w) (<= 0 r0 (- h H)) (<= 0 c0 (- w W)) (inside? anchor)
            (search (list anchor) (remove anchor pieces)))))
   (define assembled (paint-cells (empty-grid h w bg) (append-map cells solution)))
   (define (regions triples)
     (filter (lambda (o) (not (= (obj-color o) base)))
             (objects (paint-cells (empty-grid h w bg) triples) bg)))
   (define final-regions (regions (append-map cells solution)))
   (define raw-regions (append-map (lambda (p) (regions (cells p))) solution))
   (define available (if (equal? mode "raw_largest") raw-regions final-regions))
   (define selected
     (cond
       ((or (equal? mode "assembly") (null? available)) '())
       ((equal? mode "all_regions") available)
       ((equal? mode "smallest_region")
        (filter (lambda (o) (= (obj-size o) (apply min (map obj-size available)))) available))
       ((equal? mode "first_region") (list (first available)))
       (else (filter (lambda (o) (= (obj-size o) (apply max (map obj-size available)))) available))))
   (for/fold ((out assembled)) ((o selected)) (recolor-cells out (obj-cells o) marker)))))

Provenance

Generator
generators/public_eval_446ef5d2/generator.py
Notes and decisions
generators/public_eval_446ef5d2/notes.md
Review label
reviewed_safe
Generator SHA-256
5726c45005a4ddfb0da8b963f2823455fefb5050b7791121816a4edf31c25148
Rule hash
20fd169551da
Sources
evaluation, public_eval:446ef5d2
Lesson seeds
20261108, 20261109, 20261110, 20261111, 20261112
Reproduce lesson 1
arcpuzzles generate public_eval_446ef5d2 --count 1 --seed 20261108 --test 1