aboutsummaryrefslogtreecommitdiff
path: root/day04.scm
diff options
context:
space:
mode:
authorJuan Marín Noguera <juan@mnpi.eu>2024-12-05 12:07:23 +0100
committerJuan Marín Noguera <juan@mnpi.eu>2024-12-05 12:07:23 +0100
commitdc2d61ff735af1b3a61b0ad5d941cec7644ad23f (patch)
tree68c5ecadad39c27d3b3ff2125763d2e25dbdfb9c /day04.scm
parentb299763c6b81511a9d0212cb8cf428028809a441 (diff)
Put all of day 04 in the same file
In the beginning I thought of using modular components, but this would mean that I would have to retest previous days if I want to make a change to the implementation. Thus, for learning purposes, I prefer to keep everything in one file.
Diffstat (limited to 'day04.scm')
-rw-r--r--day04.scm19
1 files changed, 17 insertions, 2 deletions
diff --git a/day04.scm b/day04.scm
index fc4a4f4..9796f21 100644
--- a/day04.scm
+++ b/day04.scm
@@ -1,9 +1,24 @@
(define-module (day04)
#:use-module (ice-9 rdelim)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
- #:use-module (srfi srfi-41)
- #:use-module (util))
+ #:use-module (srfi srfi-41))
+
+(define-record-type <point> (point i j) point?
+ (i point-i)
+ (j point-j))
+
+(define (square i1 j1 i2 j2)
+ (define (row i)
+ (stream-map (cut point i <>) (stream-range j1 j2)))
+ (stream-concat (stream-map row (stream-range i1 i2))))
+
+(define (array-point arr pt)
+ (array-ref arr (point-i pt) (point-j pt)))
+
+(define (point-add pt i j)
+ (point (+ (point-i pt) i) (+ (point-j pt) j)))
(define* (read-input #:optional (port (current-input-port)))
(define (read-lines acc)