diff options
author | Matias Linares <matias.linares@comprandoengrupo.net> | 2024-12-02 10:18:15 -0300 |
---|---|---|
committer | Matias Linares <matias.linares@comprandoengrupo.net> | 2024-12-02 10:18:15 -0300 |
commit | 2e633775d14eaa246af901b0d64542192f3c2810 (patch) | |
tree | 05a3413064f5b39b29eb81a372890b913f28ed87 /2024/day02/main.scm | |
parent | e309f81f40a2d01513060f7bd07daaeb5ae78ad6 (diff) | |
download | advent-of-code-2e633775d14eaa246af901b0d64542192f3c2810.tar.gz |
Add part2 of day2 2024
Diffstat (limited to '2024/day02/main.scm')
-rwxr-xr-x | 2024/day02/main.scm | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/2024/day02/main.scm b/2024/day02/main.scm index 310f72e..07f0a4d 100755 --- a/2024/day02/main.scm +++ b/2024/day02/main.scm @@ -38,9 +38,26 @@ 1 0)) reports)))) +(define (indexes report) + (let ((retval '())) + (do ((i (1- (length report)) (1- i))) + ((< i 0)) + (set! retval (cons i retval))) + retval)) + +(define (gen-reports report) + (cons report (map (lambda (idx) + (remove-nth report idx)) (indexes report)))) + +(define (safe-report-with-toleration? report) + (any safe-report? (gen-reports report))) + (define (part2 lines) (let ((reports (lines->number-list lines))) - 0)) + (apply + (map (lambda (r) + (if (safe-report-with-toleration? r) + 1 + 0)) reports)))) (define (main) (let ((lines (file->list "input.txt"))) |