aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
Diffstat (limited to '2024')
-rw-r--r--2024/aoc-utils.scm12
-rwxr-xr-x2024/day02/main.scm19
2 files changed, 30 insertions, 1 deletions
diff --git a/2024/aoc-utils.scm b/2024/aoc-utils.scm
index 7fafcc6..98e83cd 100644
--- a/2024/aoc-utils.scm
+++ b/2024/aoc-utils.scm
@@ -15,3 +15,15 @@
(map (lambda (line)
(map string->number (string-split line #\Space)))
lines))
+
+(define (remove-nth l n)
+ "Remove the `N' element from `L', returning a new list."
+ (append (list-head l n) (list-tail l (1+ n))))
+
+(define (indexes lst)
+ "Get the indexes for `lst'."
+ (let ((retval '()))
+ (do ((i (1- (length lst)) (1- i)))
+ ((< i 0))
+ (set! retval (cons i retval)))
+ retval))
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")))