diff options
| author | Mistivia <i@mistivia.com> | 2024-02-20 00:42:16 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-02-20 00:42:16 +0800 |
| commit | bebb8946d29069b2acb10db71c8c9203ed4ae922 (patch) | |
| tree | 66ee2e321cbb413baaf32661195f2c734546eba0 /advent-of-code/2023/06 | |
| parent | 3a4e5447a79096d813cdaf4498b9a1e2c086b7ff (diff) | |
λ looks cool & format code
Diffstat (limited to 'advent-of-code/2023/06')
| -rw-r--r-- | advent-of-code/2023/06/1.rkt | 32 | ||||
| -rw-r--r-- | advent-of-code/2023/06/2.rkt | 28 |
2 files changed, 30 insertions, 30 deletions
diff --git a/advent-of-code/2023/06/1.rkt b/advent-of-code/2023/06/1.rkt index ea0d013..5496476 100644 --- a/advent-of-code/2023/06/1.rkt +++ b/advent-of-code/2023/06/1.rkt @@ -3,11 +3,11 @@ (define in (open-input-file "input")) (define (read-num-list) - (define line (read-line in)) - (map - string->number - (string-split - (cadr (string-split (string-trim line) ":"))))) + (define line (read-line in)) + (map + string->number + (string-split + (cadr (string-split (string-trim line) ":"))))) (define times (read-num-list)) (define distances (read-num-list)) @@ -15,18 +15,18 @@ (define games (map cons times distances)) (define (calc time hold-time) - (* hold-time (- time hold-time))) + (* hold-time (- time hold-time))) (define (solve time distance) - (define (loop counter hold-time) - (if (> hold-time time) - counter - (if (> (calc time hold-time) distance) - (loop (+ 1 counter) (+ 1 hold-time)) - (loop counter (+ 1 hold-time))))) - (loop 0 0)) + (define (loop counter hold-time) + (if (> hold-time time) + counter + (if (> (calc time hold-time) distance) + (loop (+ 1 counter) (+ 1 hold-time)) + (loop counter (+ 1 hold-time))))) + (loop 0 0)) -(display (apply * (map - (lambda (x) (solve (car x) (cdr x))) - games))) +(display (apply * (map + (λ (x) (solve (car x) (cdr x))) + games))) (newline) diff --git a/advent-of-code/2023/06/2.rkt b/advent-of-code/2023/06/2.rkt index 5d124e0..2d666ed 100644 --- a/advent-of-code/2023/06/2.rkt +++ b/advent-of-code/2023/06/2.rkt @@ -3,27 +3,27 @@ (define in (open-input-file "input")) (define (read-num) - (define line (read-line in)) - (string->number - (apply - string-append - (string-split - (cadr (string-split (string-trim line) ":")))))) + (define line (read-line in)) + (string->number + (apply + string-append + (string-split + (cadr (string-split (string-trim line) ":")))))) (define time (read-num)) (define distance (read-num)) (define (calc time hold-time) - (* hold-time (- time hold-time))) + (* hold-time (- time hold-time))) (define (solve time distance) - (define (loop counter hold-time) - (if (> hold-time time) - counter - (if (> (calc time hold-time) distance) - (loop (+ 1 counter) (+ 1 hold-time)) - (loop counter (+ 1 hold-time))))) - (loop 0 0)) + (define (loop counter hold-time) + (if (> hold-time time) + counter + (if (> (calc time hold-time) distance) + (loop (+ 1 counter) (+ 1 hold-time)) + (loop counter (+ 1 hold-time))))) + (loop 0 0)) (display (solve time distance)) (newline) |
