adventofcode

https://adventofcode.com/
Log | Files | Refs

commit c3a569abeeebe6841b4a41cc2492e4159be73bfd
parent 3c6d5fbfb9430778387fcede2d0b6b990a8e8556
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Tue,  1 Dec 2020 22:46:18 +0000

part 2 complete, didn't get filtered

Diffstat:
M2020/puzzle_1.scm | 37++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/2020/puzzle_1.scm b/2020/puzzle_1.scm @@ -11,23 +11,26 @@ (reverse lines)) (loop (read-line p) (cons (string->number line) lines)))))) -(define (walk-list-compare lst fun) - (if (not (list? lst)) - (if (= 2020 (+ lst fun)) - (display (* lst fun))) - (if (not (null? lst)) - (begin - (walk-list-compare (car lst) fun) - (walk-list-compare (cdr lst) fun))))) +(define (part-1 x a b) + (if (and (not (null? a)) (= 2020 (+ (car a) (car b)))) + (list (car a) (car b) (* (car a) (car b))) + (if (null? a) + (if (null? b) + 0 + (part-1 x x (cdr b))) + (part-1 x (cdr a) b)))) -(define (do-thing lst fun blep) - (if (not (list? lst)) - (fun blep lst) - (if (not (null? lst)) - (begin - (do-thing (car lst) fun blep) - (do-thing (cdr lst) fun blep))))) +(define (part-2 x a b c) + (if (and (not (null? a)) (not (null? b)) (= 2020 (+ (car a) (car b) (car c)))) + (list (car a) (car b) (car c) (* (car a) (car b) (car c))) + (if (null? a) + (if (null? b) + (if (null? c) + 0 + (part-2 x a x (cdr c))) + (part-2 x x (cdr b) c)) + (part-2 x (cdr a) b c)))) (define entries (read-lines "files/1.txt")) - -(do-thing entries walk-list-compare entries) +(part-1 entries entries entries) +(part-2 entries entries entries entries)