Use specialized not-equals functions (!=, nchar=?) instead of general neq? function.
This commit is contained in:
parent
abfec61775
commit
e3d0c0aee8
8
lib.rkt
8
lib.rkt
|
@ -21,7 +21,7 @@
|
|||
uncurry
|
||||
|
||||
sum
|
||||
!= neq?
|
||||
!= nchar=?
|
||||
nzero?
|
||||
negate
|
||||
pos-or-zero
|
||||
|
@ -122,9 +122,9 @@
|
|||
(define (!= n1 n2)
|
||||
(not (= n1 n2)))
|
||||
|
||||
;; neq : any -> any -> boolean
|
||||
(define (neq? v1 v2)
|
||||
(not (eq? v1 v2)))
|
||||
;; nchar=? : char -> char -> boolean
|
||||
(define (nchar=? c1 c2)
|
||||
(not (char=? c1 c2)))
|
||||
|
||||
;; nzero? : number -> boolean
|
||||
(define (nzero? n)
|
||||
|
|
10
src/04.rkt
10
src/04.rkt
|
@ -19,12 +19,12 @@
|
|||
(define (has-group-of-two? cs)
|
||||
(cond [(< (length cs) 2) #f]
|
||||
[(= (length cs) 2)
|
||||
(eq? (first cs) (second cs))]
|
||||
(char=? (first cs) (second cs))]
|
||||
[else
|
||||
(or (and (eq? (first cs)
|
||||
(second cs))
|
||||
(neq? (second cs)
|
||||
(third cs)))
|
||||
(or (and (char=? (first cs)
|
||||
(second cs))
|
||||
(nchar=? (second cs)
|
||||
(third cs)))
|
||||
(has-group-of-two? (dropf cs (λ (c) (eq? c (first cs))))))]))
|
||||
|
||||
(define-values (part1 part2)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
(* ones twos)))
|
||||
|
||||
(define part2
|
||||
(let* ([image (map (∂ findf (∂ neq? #\2)) (transpose layers))])
|
||||
(let* ([image (map (∂ findf (∂ nchar=? #\2)) (transpose layers))])
|
||||
(show-list-grid pixel-hash (chunks-of image width))))
|
||||
|
||||
(show-solution part1 #f)
|
|
@ -53,7 +53,7 @@
|
|||
(let*-values
|
||||
([(clr* st) (resume-with-output (resume clr))]
|
||||
[(δ st) (resume-with-output st)])
|
||||
(cond [(neq? clr clr*)
|
||||
(cond [(!= clr clr*)
|
||||
(hash-set! hull xy clr*)])
|
||||
(let* ([dir (update-dir dir δ)]
|
||||
[xy (update-pos dir xy)])
|
||||
|
|
Loading…
Reference in New Issue