simpler
This commit is contained in:
@@ -36,15 +36,14 @@
|
||||
; returns a new list of coordinates
|
||||
(define (fold coords axis-position)
|
||||
(let-values [((axis position) (apply values axis-position))]
|
||||
(let [(position*2 (* position 2))]
|
||||
(define (mirror-x x y) (list (if (> x position) (- position*2 x) x) y))
|
||||
(define (mirror-y x y) (list x (if (> y position) (- position*2 y) y)))
|
||||
(let [(mirror (if (char=? axis #\x) mirror-x mirror-y))]
|
||||
(define (folder output coord)
|
||||
(let* [(mirrored (apply mirror coord))]
|
||||
; add mirrored coord only if it wasn't in output already
|
||||
(if (member mirrored output) output (cons mirrored output))))
|
||||
(fold-left folder '() coords)))))
|
||||
(let* [(position*2 (* position 2))
|
||||
(mirror (if (char=? axis #\x)
|
||||
(lambda (x y) (list (if (> x position) (- position*2 x) x) y))
|
||||
(lambda (x y) (list x (if (> y position) (- position*2 y) y)))))
|
||||
(transform (lambda (output coord)
|
||||
(let [(mirrored (apply mirror coord))]
|
||||
(if (member mirrored output) output (cons mirrored output)))))]
|
||||
(fold-left transform '() coords))))
|
||||
|
||||
(call-with-input-file
|
||||
"input"
|
||||
|
||||
Reference in New Issue
Block a user