aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2023/05/1.rkt
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-02-20 00:42:16 +0800
committerMistivia <i@mistivia.com>2024-02-20 00:42:16 +0800
commitbebb8946d29069b2acb10db71c8c9203ed4ae922 (patch)
tree66ee2e321cbb413baaf32661195f2c734546eba0 /advent-of-code/2023/05/1.rkt
parent3a4e5447a79096d813cdaf4498b9a1e2c086b7ff (diff)
λ looks cool & format code
Diffstat (limited to 'advent-of-code/2023/05/1.rkt')
-rwxr-xr-xadvent-of-code/2023/05/1.rkt32
1 files changed, 16 insertions, 16 deletions
diff --git a/advent-of-code/2023/05/1.rkt b/advent-of-code/2023/05/1.rkt
index f0ad5ed..352e10c 100755
--- a/advent-of-code/2023/05/1.rkt
+++ b/advent-of-code/2023/05/1.rkt
@@ -2,11 +2,11 @@
(define port (open-input-file "input"))
-(define seed
+(define seed
(let ()
- (define nums-str
+ (define nums-str
(string-trim
- (list-ref (string-split (read-line port) ":") 1)))
+ (list-ref (string-split (read-line port) ":") 1)))
(map string->number (string-split nums-str " "))))
(begin (read-line port) (void))
@@ -19,9 +19,9 @@
(define (loop ret)
(define line (string-trim (read-line-convert-eof port)))
(if (= 0 (string-length line))
- (reverse ret)
- (loop (cons (map string->number (string-split line " "))
- ret))))
+ (reverse ret)
+ (loop (cons (map string->number (string-split line " "))
+ ret))))
(read-line port)
(loop '()))
@@ -38,16 +38,16 @@
(define (mapper x)
(define (loop the-map)
(if (null? the-map)
- x
- (let ()
- (define cur-map (car the-map))
- (define target (car cur-map))
- (define start (cadr cur-map))
- (define len (caddr cur-map))
- (if (and (>= x start)
- (<= x (+ start len)))
- (+ target (- x start))
- (loop (cdr the-map))))))
+ x
+ (let ()
+ (define cur-map (car the-map))
+ (define target (car cur-map))
+ (define start (cadr cur-map))
+ (define len (caddr cur-map))
+ (if (and (>= x start)
+ (<= x (+ start len)))
+ (+ target (- x start))
+ (loop (cdr the-map))))))
(loop the-map))
mapper)