aboutsummaryrefslogtreecommitdiff
path: root/2024/day02/main.scm
diff options
context:
space:
mode:
authorMatias Linares <matias.linares@comprandoengrupo.net>2024-12-02 10:18:15 -0300
committerMatias Linares <matias.linares@comprandoengrupo.net>2024-12-02 10:18:15 -0300
commit2e633775d14eaa246af901b0d64542192f3c2810 (patch)
tree05a3413064f5b39b29eb81a372890b913f28ed87 /2024/day02/main.scm
parente309f81f40a2d01513060f7bd07daaeb5ae78ad6 (diff)
downloadadvent-of-code-2e633775d14eaa246af901b0d64542192f3c2810.tar.gz
Add part2 of day2 2024
Diffstat (limited to '2024/day02/main.scm')
-rwxr-xr-x2024/day02/main.scm19
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")))