puzzle_3.scm (766B)
1 (define (check-slice slice x) 2 (if (char=? (string-ref slice (modulo x (string-length slice))) ##) 1 0)) 3 4 (define (count-trees tree-map slope) 5 (define (recurse-trees tree-map x y slope) 6 (if (not (null? tree-map)) 7 (let ((parity (= (modulo y (car (cdr slope))) 0))) 8 (+ (if parity 9 (+ (check-slice (car tree-map) x)) 0) 10 (recurse-trees (cdr tree-map) (+ x (if parity (car slope) 0)) (+ y 1) slope))) 11 0)) 12 (recurse-trees tree-map 0 0 slope)) 13 14 (load "read_lines.scm") 15 (define input (read-lines "files/3.txt" (lambda (x) x))) 16 (define slopes '((1 1) (3 1) (5 1) (7 1) (1 2))) 17 18 (display (count-trees input (car (cdr slopes)))) (newline) 19 (display (apply * (map (lambda (slope) (count-trees input slope)) slopes))) (newline)