diff options
Diffstat (limited to 'aoc2020/day-10/day-10.rkt')
-rw-r--r-- | aoc2020/day-10/day-10.rkt | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/aoc2020/day-10/day-10.rkt b/aoc2020/day-10/day-10.rkt deleted file mode 100644 index 77d9bb7..0000000 --- a/aoc2020/day-10/day-10.rkt +++ /dev/null @@ -1,37 +0,0 @@ -#lang racket - -(require advent-of-code - threading - algorithms - memoize) - -;; part 1 -(define adapters - (~> (fetch-aoc-input (find-session) 2020 10) - (string-split "\n") - (map string->number _) - (sort <) - ((λ (xs) (flatten (list 0 xs (+ 3 (last xs)))))))) - -(~>> adapters - (sliding _ 2) - (map (match-lambda - [(list b a) (- a b)])) - (group-by identity) - (map length) - (apply *)) - -;; part 2 -(define subpaths - (for*/hash ([adapter (in-list adapters)]) - (define predecessor-candidates (inclusive-range (+ 1 adapter) (+ 3 adapter))) - (values adapter (filter (λ (p) (member p adapters)) predecessor-candidates)))) - -(define/memo (find-paths from to) - (define paths (hash-ref subpaths from 'failed)) - (match paths - ['failed 0] - [(list-no-order (== to) _ ...) 1] - [ts (for/sum ([t (in-list ts)]) (find-paths t to))])) - -(find-paths (first adapters) (last adapters)) |