diff options
-rw-r--r-- | aoc2018/day-05/day-05.rkt | 31 | ||||
-rw-r--r-- | aoc2018/day-06/day-06.rkt | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/aoc2018/day-05/day-05.rkt b/aoc2018/day-05/day-05.rkt new file mode 100644 index 0000000..a78f5b5 --- /dev/null +++ b/aoc2018/day-05/day-05.rkt @@ -0,0 +1,31 @@ +#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 new file mode 100644 index 0000000..6f1f7b4 --- /dev/null +++ b/aoc2018/day-06/day-06.rkt @@ -0,0 +1 @@ +#lang racket |