master
Matthew Butterick 7 years ago
parent 4b8627131a
commit 18628e6092

@ -37,11 +37,12 @@
(define vals (make-hash)) (define vals (make-hash))
(define (neighbor-sum n) (define (neighbor-sum n)
(define c (nth-coordinate n)) (define c (nth-coordinate n))
(define neighbor-offsets '(1 1+i +i -1+i -1 -1-1i -i 1-i))
(hash-ref! vals c (λ () (if (= c 0) (hash-ref! vals c (λ () (if (= c 0)
1 1
(for/sum ([n (in-list neighbor-offsets)]) (for*/sum ([h (in-list '(-1 0 1))]
(hash-ref vals (+ c n) 0)))))) [v (in-list '(-1 0 1))])
(define neighbor (+ h (* +i v)))
(hash-ref vals (+ c neighbor) 0))))))
(define (larger-sum x) (define (larger-sum x)
(for*/first ([n (in-naturals 1)] (for*/first ([n (in-naturals 1)]