aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2023/07
diff options
context:
space:
mode:
Diffstat (limited to 'advent-of-code/2023/07')
-rw-r--r--advent-of-code/2023/07/1.rkt62
-rw-r--r--advent-of-code/2023/07/2.rkt62
2 files changed, 62 insertions, 62 deletions
diff --git a/advent-of-code/2023/07/1.rkt b/advent-of-code/2023/07/1.rkt
index a22571d..286a0e8 100644
--- a/advent-of-code/2023/07/1.rkt
+++ b/advent-of-code/2023/07/1.rkt
@@ -1,18 +1,18 @@
#lang racket
-(define input
+(define input
(with-input-from-file "input"
- (lambda ()
+ (λ ()
(let loop ((cards '()))
(define line (read-line))
(if (or (eof-object? line)
- (= 0 (string-length line)))
- (reverse cards)
- (let ()
- (define splited-line (string-split line))
- (define hand (car splited-line))
- (define bid (string->number (cadr splited-line)))
- (loop (cons (list hand bid) cards))))))))
+ (= 0 (string-length line)))
+ (reverse cards)
+ (let ()
+ (define splited-line (string-split line))
+ (define hand (car splited-line))
+ (define bid (string->number (cadr splited-line)))
+ (loop (cons (list hand bid) cards))))))))
(define (card-number char)
(cond ((eq? char #\A) 12)
@@ -27,51 +27,51 @@
(define vec (make-vector 13 0))
(let loop ((i 0))
(if (>= i 5)
- (vector->list (vector-sort vec >))
- (let ()
- (define index (card-number (string-ref hand i)))
- (vector-set! vec index (+ 1 (vector-ref vec index)))
- (loop (+ i 1))))))
+ (vector->list (vector-sort vec >))
+ (let ()
+ (define index (card-number (string-ref hand i)))
+ (vector-set! vec index (+ 1 (vector-ref vec index)))
+ (loop (+ i 1))))))
(define (hand-type<? type1 type2)
(if (or (null? type1)
(null? type2))
- #f
- (if (= (car type1) (car type2))
- (hand-type<? (cdr type1) (cdr type2))
- (< (car type1) (car type2)))))
+ #f
+ (if (= (car type1) (car type2))
+ (hand-type<? (cdr type1) (cdr type2))
+ (< (car type1) (car type2)))))
(define (hand-type=? type1 type2)
(if (null? type1)
- #t
- (if (= (car type1) (car type2))
- (hand-type=? (cdr type1) (cdr type2))
- #f)))
+ #t
+ (if (= (car type1) (car type2))
+ (hand-type=? (cdr type1) (cdr type2))
+ #f)))
(define (raw-hand<? hand1 hand2)
- (define h1 (map card-number (string->list hand1)))
- (define h2 (map card-number (string->list hand2)))
- (hand-type<? h1 h2))
+ (define h1 (map card-number (string->list hand1)))
+ (define h2 (map card-number (string->list hand2)))
+ (hand-type<? h1 h2))
(define (hand<? hand1 hand2)
(define type1 (hand-type hand1))
(define type2 (hand-type hand2))
(if (hand-type=? type1 type2)
- (raw-hand<? hand1 hand2)
- (hand-type<? type1 type2)))
+ (raw-hand<? hand1 hand2)
+ (hand-type<? type1 type2)))
(define sorted-cards
- (sort input (lambda (a b)
+ (sort input (λ (a b)
(hand<? (car a) (car b)))))
(define (calc-points card)
- (* (cadar card) (cadr card)))
+ (* (cadar card) (cadr card)))
(define (enumerate lst)
(let loop ((i 1) (ret '()) (remain lst))
(if (null? remain)
- (reverse ret)
- (loop (+ 1 i) (cons (list (car remain) i) ret) (cdr remain)))))
+ (reverse ret)
+ (loop (+ 1 i) (cons (list (car remain) i) ret) (cdr remain)))))
(define result
(apply + (map calc-points (enumerate sorted-cards))))
diff --git a/advent-of-code/2023/07/2.rkt b/advent-of-code/2023/07/2.rkt
index 50d9526..07ff61b 100644
--- a/advent-of-code/2023/07/2.rkt
+++ b/advent-of-code/2023/07/2.rkt
@@ -1,18 +1,18 @@
#lang racket
-(define input
+(define input
(with-input-from-file "input"
- (lambda ()
+ (λ ()
(let loop ((cards '()))
(define line (read-line))
(if (or (eof-object? line)
- (= 0 (string-length line)))
- (reverse cards)
- (let ()
- (define splited-line (string-split line))
- (define hand (car splited-line))
- (define bid (string->number (cadr splited-line)))
- (loop (cons (list hand bid) cards))))))))
+ (= 0 (string-length line)))
+ (reverse cards)
+ (let ()
+ (define splited-line (string-split line))
+ (define hand (car splited-line))
+ (define bid (string->number (cadr splited-line)))
+ (loop (cons (list hand bid) cards))))))))
(define (card-number char)
(cond ((eq? char #\A) 12)
@@ -34,51 +34,51 @@
(define vec (make-vector 13 0))
(let loop ((i 0))
(if (>= i 5)
- (vector->list (joker-transform vec))
- (let ()
- (define index (card-number (string-ref hand i)))
- (vector-set! vec index (+ 1 (vector-ref vec index)))
- (loop (+ i 1))))))
+ (vector->list (joker-transform vec))
+ (let ()
+ (define index (card-number (string-ref hand i)))
+ (vector-set! vec index (+ 1 (vector-ref vec index)))
+ (loop (+ i 1))))))
(define (hand-type<? type1 type2)
(if (or (null? type1)
(null? type2))
- #f
- (if (= (car type1) (car type2))
- (hand-type<? (cdr type1) (cdr type2))
- (< (car type1) (car type2)))))
+ #f
+ (if (= (car type1) (car type2))
+ (hand-type<? (cdr type1) (cdr type2))
+ (< (car type1) (car type2)))))
(define (hand-type=? type1 type2)
(if (null? type1)
- #t
- (if (= (car type1) (car type2))
- (hand-type=? (cdr type1) (cdr type2))
- #f)))
+ #t
+ (if (= (car type1) (car type2))
+ (hand-type=? (cdr type1) (cdr type2))
+ #f)))
(define (raw-hand<? hand1 hand2)
- (define h1 (map card-number (string->list hand1)))
- (define h2 (map card-number (string->list hand2)))
- (hand-type<? h1 h2))
+ (define h1 (map card-number (string->list hand1)))
+ (define h2 (map card-number (string->list hand2)))
+ (hand-type<? h1 h2))
(define (hand<? hand1 hand2)
(define type1 (hand-type hand1))
(define type2 (hand-type hand2))
(if (hand-type=? type1 type2)
- (raw-hand<? hand1 hand2)
- (hand-type<? type1 type2)))
+ (raw-hand<? hand1 hand2)
+ (hand-type<? type1 type2)))
(define sorted-cards
- (sort input (lambda (a b)
+ (sort input (λ (a b)
(hand<? (car a) (car b)))))
(define (calc-points card)
- (* (cadar card) (cadr card)))
+ (* (cadar card) (cadr card)))
(define (enumerate lst)
(let loop ((i 1) (ret '()) (remain lst))
(if (null? remain)
- (reverse ret)
- (loop (+ 1 i) (cons (list (car remain) i) ret) (cdr remain)))))
+ (reverse ret)
+ (loop (+ 1 i) (cons (list (car remain) i) ret) (cdr remain)))))
(define result
(apply + (map calc-points (enumerate sorted-cards))))