1
0
Fork 0

Use specialized not-equals functions (!=, nchar=?) instead of general neq? function.

This commit is contained in:
Jonathan Chan 2019-12-15 22:57:31 -08:00
parent abfec61775
commit e3d0c0aee8
4 changed files with 11 additions and 11 deletions

View File

@ -21,7 +21,7 @@
uncurry uncurry
sum sum
!= neq? != nchar=?
nzero? nzero?
negate negate
pos-or-zero pos-or-zero
@ -122,9 +122,9 @@
(define (!= n1 n2) (define (!= n1 n2)
(not (= n1 n2))) (not (= n1 n2)))
;; neq : any -> any -> boolean ;; nchar=? : char -> char -> boolean
(define (neq? v1 v2) (define (nchar=? c1 c2)
(not (eq? v1 v2))) (not (char=? c1 c2)))
;; nzero? : number -> boolean ;; nzero? : number -> boolean
(define (nzero? n) (define (nzero? n)

View File

@ -19,11 +19,11 @@
(define (has-group-of-two? cs) (define (has-group-of-two? cs)
(cond [(< (length cs) 2) #f] (cond [(< (length cs) 2) #f]
[(= (length cs) 2) [(= (length cs) 2)
(eq? (first cs) (second cs))] (char=? (first cs) (second cs))]
[else [else
(or (and (eq? (first cs) (or (and (char=? (first cs)
(second cs)) (second cs))
(neq? (second cs) (nchar=? (second cs)
(third cs))) (third cs)))
(has-group-of-two? (dropf cs (λ (c) (eq? c (first cs))))))])) (has-group-of-two? (dropf cs (λ (c) (eq? c (first cs))))))]))

View File

@ -25,7 +25,7 @@
(* ones twos))) (* ones twos)))
(define part2 (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-list-grid pixel-hash (chunks-of image width))))
(show-solution part1 #f) (show-solution part1 #f)

View File

@ -53,7 +53,7 @@
(let*-values (let*-values
([(clr* st) (resume-with-output (resume clr))] ([(clr* st) (resume-with-output (resume clr))]
[(δ st) (resume-with-output st)]) [(δ st) (resume-with-output st)])
(cond [(neq? clr clr*) (cond [(!= clr clr*)
(hash-set! hull xy clr*)]) (hash-set! hull xy clr*)])
(let* ([dir (update-dir dir δ)] (let* ([dir (update-dir dir δ)]
[xy (update-pos dir xy)]) [xy (update-pos dir xy)])