adventofcode

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

commit ba6290ab3646f8dd5d437ff8c7ace741a9b716ab
parent 3e1cf6949b012f31e5b2d9ba569eae2ad5d9416f
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Thu,  3 Dec 2020 13:16:17 +0000

renaming variables

Diffstat:
M2020/puzzle_3.scm | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/2020/puzzle_3.scm b/2020/puzzle_3.scm @@ -1,17 +1,17 @@ (define (check-slice slice x) (if (char=? (string-ref slice (modulo x (string-length slice))) ##) 1 0)) -(define (count-trees tree-map x y x-offset y-offset) +(define (count-trees tree-map x y slope) (if (not (null? tree-map)) - (let ((parity (= (modulo y y-offset) 0))) + (let ((parity (= (modulo y (car (cdr slope))) 0))) (+ (if parity (+ (check-slice (car tree-map) x)) 0) - (count-trees (cdr tree-map) (+ x (if parity x-offset 0)) (+ y 1) x-offset y-offset))) + (count-trees (cdr tree-map) (+ x (if parity (car slope) 0)) (+ y 1) slope))) 0)) (load "read_lines.scm") (define input (read-lines "files/3.txt" (lambda (x) x))) (define slopes '((1 1) (3 1) (5 1) (7 1) (1 2))) -(display (count-trees input 0 0 3 1)) (newline) -(display (apply * (map (lambda (x) (count-trees input 0 0 (car x) (car (cdr x)))) slopes))) (newline) +(display (count-trees input 0 0 (car (cdr slopes)))) (newline) +(display (apply * (map (lambda (slope) (count-trees input 0 0 slope)) slopes))) (newline)