#lang curly-fn racket (require "scripts/aoc.rkt") ;; solution for day 10 ;; helper functions here (define (part1 input) (define sorted (sort input <)) (define deltas (for/list ([a (in-list (rest sorted))] [b (in-list sorted)]) (- a b))) (define ones (count #{= 1 %} deltas)) (define threes (count #{= 3 %} deltas)) ;; idk but add1 to both because reasons(tm) (* (add1 ones) (add1 threes))) (define (part2 input) ;; sort ;; also add 0 (define is (cons 0 (sort input <))) ;; make graph (define-values [edges _] (for/fold ([edges '()] [lst (rest is)]) ([x (in-list is)]) (define res3 (if (and (> (length lst) 2) (<= (- (third lst) 3) x)) (list (list x (third lst))) '())) (define res2 (if (and (> (length lst) 1) (<= (- (second lst) 3) x)) (list (list x (second lst))) '())) (define res1 (if (and (> (length lst) 0) (<= (- (first lst) 3) x)) (list (list x (first lst))) '())) (values (append edges res1 res2 res3) (if (empty? lst) '() (rest lst))))) ;; yay graph (define G (directed-graph edges)) ;; the node we want (define wanted (last is)) ;; count the total number of paths that end in wanted (define/memoized (count-paths node) (cond [(= node wanted) 1] ;; there's one path to the wanted node from wherever we went ;; add up all possible paths recursively [else (for/sum ([x (in-neighbors G node)]) (count-paths x))])) ;; yeet (count-paths 0)) (module+ test (require rackunit) (check-equal? 8 (part2 '(16 10 15 5 1 11 7 19 6 12 4)))) (module+ main (define input (map string->number (file->lines "inputs/10"))) ;; part 1 (answer 10 1 (part1 input)) ;; part 2 (answer 10 2 (part2 input)) (displayln "meow"))