|
|
|
@ -13,15 +13,11 @@
|
|
|
|
|
#'(#%module-begin
|
|
|
|
|
(time (STARS (list LINE ...)))))
|
|
|
|
|
|
|
|
|
|
(define (populate-hash! chars lines)
|
|
|
|
|
(for* ([(line lidx) (in-indexed lines)]
|
|
|
|
|
(define (traverse lines #:count-steps [count-steps? #f])
|
|
|
|
|
(define chars (for*/hasheqv ([(line lidx) (in-indexed lines)]
|
|
|
|
|
[(c cidx) (in-indexed (string->list line))]
|
|
|
|
|
#:unless (char=? c #\space))
|
|
|
|
|
(hash-set! chars (+ lidx (* +i cidx)) c)))
|
|
|
|
|
|
|
|
|
|
(define (traverse lines #:count-steps [count-steps? #f])
|
|
|
|
|
(define chars (make-hasheqv))
|
|
|
|
|
(populate-hash! chars lines)
|
|
|
|
|
(values (+ lidx (* +i cidx)) c)))
|
|
|
|
|
(define start (for/first ([k (in-hash-keys chars)]
|
|
|
|
|
#:when (zero? (real-part k)))
|
|
|
|
|
k))
|
|
|
|
@ -31,7 +27,7 @@
|
|
|
|
|
(cond
|
|
|
|
|
[here-char
|
|
|
|
|
(define next-dir (if (char=? here-char #\+)
|
|
|
|
|
(if (hash-has-key? chars (+ here (* dir +i))) (* dir +i) (* dir -i))
|
|
|
|
|
(if (hash-has-key? chars (+ here (* dir right))) (* dir right) (* dir left))
|
|
|
|
|
dir))
|
|
|
|
|
(loop (+ here next-dir) next-dir (cons here-char path))]
|
|
|
|
|
[count-steps? (length path)]
|
|
|
|
|