summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamp2023-12-11 21:35:38 +0000
committerlamp2023-12-11 21:35:38 +0000
commitf87b9321de3774b14b7fb6187666b47007a4bd66 (patch)
tree54f2e79ca0e378f7d5c020d7439794403813d807
parentcd6a52f02a3c3d7b8e2565c3199174ba1625e899 (diff)
begin work on day 10 solutions
-rwxr-xr-x10.scm42
-rw-r--r--10s.txt5
2 files changed, 47 insertions, 0 deletions
diff --git a/10.scm b/10.scm
new file mode 100755
index 0000000..15c4b1c
--- /dev/null
+++ b/10.scm
@@ -0,0 +1,42 @@
+#!/usr/bin/env -S guile -s
+!#
+(use-modules (ice-9 textual-ports)
+ (srfi srfi-1))
+
+(define (read-lines port)
+ (letrec ((loop (lambda (l ls)
+ (if (eof-object? l)
+ ls
+ (loop (get-line port) (cons l ls))))))
+ (reverse (loop (get-line port) '()))))
+
+(define (candidates-for type pos)
+ (let ((x (car pos))
+ (y (cdr pos)))
+ (cond ((equal? type #\|) `(,(cons x (1+ y))
+ ,(cons x (1- y))))
+ ((equal? type #\-) `(,(cons (1+ x) y)
+ ,(cons (1- x) y)))
+ ((equal? type #\L) `(,(cons x (1- y))
+ ,(cons (1+ x) y)))
+ ((equal? type #\J) `(,(cons x (1- y))
+ ,(cons (1- x) y)))
+ ((equal? type #\7) `(,(cons (1- x) y)
+ ,(cons x (1+ y))))
+ ((equal? type #\F) `(,(cons x (1+ y))
+ ,(cons (1+ x) y)))
+ ((equal? type #\S) `(,(cons x (1+ y))
+ ,(cons x (1- y))
+ ,(cons (1+ x) y)
+ ,(cons (1- x) y)))
+ ((equal? type #\.) '()))))
+
+(let* ((port (open-input-file "10s.txt"))
+ (lines (read-lines port))
+ (candidates '((0 . 2)))
+ (seen '()))
+ (close-port port)
+ (while (not (null? candidates))
+ (set! candidates (append! (cdr candidates) (filter (lambda (x) (member x seen)) (candidates-for (string-ref (list-ref lines (cdar candidates)) (caar candidates)) (car candidates)))))
+ (display candidates)
+ (newline)))
diff --git a/10s.txt b/10s.txt
new file mode 100644
index 0000000..3aea4dd
--- /dev/null
+++ b/10s.txt
@@ -0,0 +1,5 @@
+7-F7-
+.FJ|7
+SJLL7
+|F--J
+LJ.LJ