diff options
author | HJ <thechairman@thechairman.info> | 2021-12-09 18:05:04 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2021-12-09 18:05:04 -0500 |
commit | 527bc4762f9c66c9244f0ac1fbee6357478ac9ef (patch) | |
tree | ecd3ffc97de5aab201699f93aab1e0417ac3d25d /2020/day-01/day-01.rkt | |
download | gleam_aoc-527bc4762f9c66c9244f0ac1fbee6357478ac9ef.tar.gz gleam_aoc-527bc4762f9c66c9244f0ac1fbee6357478ac9ef.zip |
putting all my solutions together in 1 repository
Diffstat (limited to '2020/day-01/day-01.rkt')
-rw-r--r-- | 2020/day-01/day-01.rkt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/2020/day-01/day-01.rkt b/2020/day-01/day-01.rkt new file mode 100644 index 0000000..56c0b87 --- /dev/null +++ b/2020/day-01/day-01.rkt @@ -0,0 +1,23 @@ +#lang racket +(require "../../jj-aoc.rkt" + threading) + +(define entries + (~>> (open-day 01 2020) + (port->list read) + list->set)) + +;; part 1 +(define (look-for-complement xs) + (define x (set-first xs)) + (cond + [(set-member? xs (- 2020 x)) (* x (- 2020 x))] + [else (look-for-complement (set-rest xs))])) + +(time (look-for-complement entries)) + +;; part 2 +(time (for*/first ([x (in-set entries)] + [y (in-set (set-subtract entries (set x)))] + #:when (set-member? (set-subtract entries (set x y)) (- 2020 x y))) + (* x y (- 2020 x y))))
\ No newline at end of file |