aboutsummaryrefslogtreecommitdiff
path: root/racket/aoc2020/day-01
diff options
context:
space:
mode:
Diffstat (limited to 'racket/aoc2020/day-01')
-rw-r--r--racket/aoc2020/day-01/day-01.rkt20
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))))