diff options
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"))) |