diff options
Diffstat (limited to 'aoc2018')
-rw-r--r-- | aoc2018/day-01/day-01.rkt | 16 | ||||
-rw-r--r-- | aoc2018/day-02/day-02.rkt | 27 | ||||
-rw-r--r-- | aoc2018/day-03/day-03.rkt | 51 | ||||
-rw-r--r-- | aoc2018/day-04/day-04.rkt | 43 | ||||
-rw-r--r-- | aoc2018/day-05/day-05.rkt | 31 | ||||
-rw-r--r-- | aoc2018/day-06/day-06.rkt | 1 |
6 files changed, 0 insertions, 169 deletions
diff --git a/aoc2018/day-01/day-01.rkt b/aoc2018/day-01/day-01.rkt deleted file mode 100644 index b18f7c9..0000000 --- a/aoc2018/day-01/day-01.rkt +++ /dev/null @@ -1,16 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(define deltas - (~>> (open-aoc-input (find-session) 2018 1 #:cache #true) port->lines (map string->number))) - -;; part 1 -(for/sum ([delta deltas]) delta) - -;; part 2 -(for/fold ([seen (set)] [current-frequency 0] #:result current-frequency) ([delta (in-cycle deltas)]) - (define new-frequency (+ current-frequency delta)) - #:final (set-member? seen new-frequency) - (values (set-add seen new-frequency) new-frequency)) diff --git a/aoc2018/day-02/day-02.rkt b/aoc2018/day-02/day-02.rkt deleted file mode 100644 index 38155fb..0000000 --- a/aoc2018/day-02/day-02.rkt +++ /dev/null @@ -1,27 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(define ids (port->lines (open-aoc-input (find-session) 2018 2 #:cache #true))) - -;; part 1 -(define (make-baskets str) - (for/fold ([baskets (hash)]) ([ch (in-string str)]) - (hash-update baskets ch add1 0))) - -(define (has-count n ht) - (member n (hash-values ht))) - -(for/fold ([two 0] [three 0] #:result (* two three)) ([id (in-list ids)]) - (define baskets (make-baskets id)) - (values (if (has-count 2 baskets) (add1 two) two) (if (has-count 3 baskets) (add1 three) three))) - -;; part 2 -(define (string-difference str1 str2) - (for/sum ([ch1 (in-string str1)] [ch2 (in-string str2)]) (if (equal? ch1 ch2) 0 1))) - -(for*/first ([id1 (in-list ids)] [id2 (in-list ids)] #:when (= 1 (string-difference id1 id2))) - (~>> (for/list ([ch1 (in-string id1)] [ch2 (in-string id2)] #:when (equal? ch1 ch2)) - ch1) - (apply string))) diff --git a/aoc2018/day-03/day-03.rkt b/aoc2018/day-03/day-03.rkt deleted file mode 100644 index b486361..0000000 --- a/aoc2018/day-03/day-03.rkt +++ /dev/null @@ -1,51 +0,0 @@ -#lang racket - -(require advent-of-code - threading - data/applicative - data/monad - megaparsack - megaparsack/text) - -(struct claim (number start-x start-y size-x size-y) #:transparent) - -(define claim/p - (do (char/p #\#) - [number <- integer/p] - (string/p " @ ") - [start-x <- integer/p] - (char/p #\,) - [start-y <- integer/p] - (string/p ": ") - [size-x <- integer/p] - (char/p #\x) - [size-y <- integer/p] - (pure (claim number start-x start-y size-x size-y)))) - -(define (parse-claim str) - (parse-result! (parse-string claim/p str))) - -(define (make-claim ht cl) - (for*/fold ([fabric ht]) - ([x (in-range (claim-start-x cl) (+ (claim-start-x cl) (claim-size-x cl)))] - [y (in-range (claim-start-y cl) (+ (claim-start-y cl) (claim-size-y cl)))]) - (hash-update fabric (cons x y) add1 0))) - -(define claims - (~> (port->lines (open-aoc-input (find-session) 2018 3 #:cache #true)) (map parse-claim _))) - -(define claimed-fabric - (for/fold ([fabric (hash)]) ([cl (in-list claims)]) - (make-claim fabric cl))) - -;; part 1 -(for/sum ([claim-count (in-list (hash-values claimed-fabric))] #:when (< 1 claim-count)) 1) - -;; part 2 -(define (uncontested-claim? fabric cl) - (for*/and ([x (in-range (claim-start-x cl) (+ (claim-start-x cl) (claim-size-x cl)))] - [y (in-range (claim-start-y cl) (+ (claim-start-y cl) (claim-size-y cl)))]) - (= 1 (hash-ref fabric (cons x y))))) - -(for/first ([cl (in-list claims)] #:when (uncontested-claim? claimed-fabric cl)) - (claim-number cl)) diff --git a/aoc2018/day-04/day-04.rkt b/aoc2018/day-04/day-04.rkt deleted file mode 100644 index 3660099..0000000 --- a/aoc2018/day-04/day-04.rkt +++ /dev/null @@ -1,43 +0,0 @@ -#lang racket - -(require advent-of-code - data/applicative - data/monad - megaparsack - megaparsack/text - threading) - -(struct entry (month day hour minute message) #:transparent) - -(define (parse-message chrs) - (define str (apply string chrs)) - (match str - ["wakes up" 'awake] - ["falls asleep" 'asleep] - [shift (~> shift (string-trim "Guard #") (string-trim " begins shift") string->number)])) - -(define entry/p - (do (string/p "[1518-") - [month <- integer/p] - (char/p #\-) - [day <- integer/p] - space/p - [hour <- integer/p] - (char/p #\:) - [minute <- integer/p] - (string/p "] ") - [message <- (many/p any-char/p)] - (pure (entry month day hour minute (parse-message message))))) - -(define (parse-entry str) - (parse-result! (parse-string entry/p str))) - -(define entries - (~> (port->lines (open-aoc-input (find-session) 2018 4 #:cache #true)) (map parse-entry _))) - -(define sorted-entries - (~> entries - (sort < #:key entry-minute) - (sort < #:key entry-hour) - (sort < #:key entry-day) - (sort < #:key entry-month))) diff --git a/aoc2018/day-05/day-05.rkt b/aoc2018/day-05/day-05.rkt deleted file mode 100644 index a78f5b5..0000000 --- a/aoc2018/day-05/day-05.rkt +++ /dev/null @@ -1,31 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(define starting-chain - (~> (fetch-aoc-input (find-session) 2018 5 #:cache #true) string-trim string->list)) - -(define (reactive-pair? ch1 ch2) - (and (equal? (char-downcase ch1) (char-downcase ch2)) (not (equal? ch1 ch2)))) - -(define (remove-reactive-pairs chs [acc '()]) - (match chs - [(list* ch1 ch2 rest-chs) - #:when (reactive-pair? ch1 ch2) - (remove-reactive-pairs rest-chs acc)] - [(list* ch rest-chs) (remove-reactive-pairs rest-chs (cons ch acc))] - [(list) (reverse acc)])) - -(define (keep-removing-reactive-pairs chs) - (define chs* (remove-reactive-pairs chs)) - (if (equal? chs chs*) (length chs) (keep-removing-reactive-pairs chs*))) - -;; part 1 -(keep-removing-reactive-pairs starting-chain) - -;; part 2 -(~>> (for/list ([letter (in-string "abcdefghijklmnopqrstuvwxyz")]) - (define tweaked-chain (filter (λ (c) (not (equal? (char-downcase c) letter))) starting-chain)) - (keep-removing-reactive-pairs tweaked-chain)) - (apply min)) diff --git a/aoc2018/day-06/day-06.rkt b/aoc2018/day-06/day-06.rkt deleted file mode 100644 index 6f1f7b4..0000000 --- a/aoc2018/day-06/day-06.rkt +++ /dev/null @@ -1 +0,0 @@ -#lang racket |