diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /racket/aoc2020/day-01/day-01.rkt | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'racket/aoc2020/day-01/day-01.rkt')
-rw-r--r-- | racket/aoc2020/day-01/day-01.rkt | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/racket/aoc2020/day-01/day-01.rkt b/racket/aoc2020/day-01/day-01.rkt new file mode 100644 index 0000000..e31c45c --- /dev/null +++ b/racket/aoc2020/day-01/day-01.rkt @@ -0,0 +1,20 @@ +#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)))) |