diff options
Diffstat (limited to '14/1.rkt')
| -rw-r--r-- | 14/1.rkt | 40 |
1 files changed, 14 insertions, 26 deletions
@@ -30,34 +30,22 @@ (define width (string-length (vector-ref mat 0))) (define (tilt) - (let loop ((y 0)) - (if (>= y height) - (void) - (let () - (let loop1 ((x 0)) - (if (>= x width) - (void) - (let () - (define c (char-at x y)) - (if (char=? #\O c) - (let () - (define new-y (find-new-pos x y)) - (move-stone x y x new-y) - (loop1 (+ 1 x))) - (loop1 (+ 1 x)))))) - (loop (+ 1 y)))))) + (do ((y 0 (+ y 1))) + ((>= y height) (void)) + (do ((x 0 (+ x 1))) + ((>= x width) (void)) + (when (char=? #\O (char-at x y)) + (move-stone x y x (find-new-pos x y)))))) (define (count) - (let loop ((x 0) (y 0) (sum 0)) - (if (>= y height) - sum - (if (>= x width) - (loop 0 (+ 1 y) sum) - (let () - (define c (char-at x y)) - (if (char=? c #\O) - (loop (+ 1 x) y (+ sum (- height y))) - (loop (+ 1 x) y sum))))))) + (define sum 0) + (do ((y 0 (+ y 1))) + ((>= y height) (void)) + (do ((x 0 (+ x 1))) + ((>= x width) (void)) + (when (char=? #\O (char-at x y)) + (set! sum (+ sum (- height y)))))) + sum) (tilt) (count)
\ No newline at end of file |
