From dc2d61ff735af1b3a61b0ad5d941cec7644ad23f Mon Sep 17 00:00:00 2001 From: Juan MarĂ­n Noguera Date: Thu, 5 Dec 2024 12:07:23 +0100 Subject: 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. --- util.scm | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 util.scm (limited to 'util.scm') diff --git a/util.scm b/util.scm deleted file mode 100644 index 44a9fa8..0000000 --- a/util.scm +++ /dev/null @@ -1,32 +0,0 @@ -(define-module (util) - #: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) - #:export (point point? point-i point-j square array-point point-add read-map)) - -(define-record-type (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-map #:optional (port (current-input-port))) - (define (read-lines acc) - (define line (read-line port)) - (if (and (not (eof-object? line)) (> (string-length line) 0)) - (read-lines (cons line acc)) - acc)) - (define strings (reverse! (read-lines '()))) - (define string->char-codes (compose (cut map char->integer <>) string->list)) - (list->typed-array 'u8 2 (map string->char-codes strings))) -- cgit v1.2.3