aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
Diffstat (limited to '2024')
-rw-r--r--2024/aoc-utils.scm4
-rwxr-xr-x2024/day04/main.scm65
2 files changed, 69 insertions, 0 deletions
diff --git a/2024/aoc-utils.scm b/2024/aoc-utils.scm
index 5deb269..ed16bfd 100644
--- a/2024/aoc-utils.scm
+++ b/2024/aoc-utils.scm
@@ -5,6 +5,7 @@
#:use-module (ice-9 rdelim)
#:export (file->list
file->str
+ file->matrix
lines->number-list))
(define (file->list filename)
@@ -15,6 +16,9 @@
(define (file->str filename)
(call-with-input-file filename read-string))
+(define (file->matrix filename)
+ (map string->list (file->list filename)))
+
(define (lines->number-list lines)
(map (lambda (line)
(map string->number (string-split line #\Space)))
diff --git a/2024/day04/main.scm b/2024/day04/main.scm
new file mode 100755
index 0000000..026e795
--- /dev/null
+++ b/2024/day04/main.scm
@@ -0,0 +1,65 @@
+#!/usr/bin/guile -s
+!#
+
+(add-to-load-path (format #f "~a/2024" (getcwd)))
+(add-to-load-path (format #f "~a/.." (dirname (current-filename))))
+
+(use-modules
+ (aoc-utils)
+ (srfi srfi-1)
+ (srfi srfi-9)
+ (srfi srfi-64)
+ (ice-9 regex)
+ (ice-9 getopt-long))
+
+(define (xmas? lst)
+ (or (equal? lst '(#\X #\M #\A #\S))
+ (equal? lst '(#\S #\A #\M #\X))))
+
+(define (get-posibilities input x y)
+ (let ((retval '()))
+ (if (> x (- (length input) 3))
+ (set! retval ()))))
+
+(define (part1 input)
+ (display input)
+ 0)
+
+(define (part2 input)
+ 0)
+
+(define (run-tests)
+ (test-begin "day03" 1)
+ (test-equal 18 (part1 (file->matrix "test.txt")))
+ (test-end "day03"))
+
+(define option-spec
+ '((help (single-char #\h) (value #f))
+ (test (single-char #\t) (value #f))))
+
+(define (help)
+ (display "main.scm [options] [FILE]
+-h, --help Display this help.
+-t, --test Run test suite
+"))
+
+(define (run-parts filename)
+ (let ((input (file->matrix filename)))
+ (display "Part1: ")
+ (display (part1 input))
+ (newline)
+ (display "Part2: ")
+ (display (part2 input))
+ (newline)))
+
+(define (main)
+ (let* ((options (getopt-long (command-line) option-spec))
+ (help-wanted? (option-ref options 'help #f))
+ (test-wanted? (option-ref options 'test #f))
+ (files (option-ref options '() '())))
+ (cond (help-wanted? (help))
+ (test-wanted? (run-tests))
+ ((= (length files) 1) (run-parts (car files)))
+ (else (help)))))
+
+(main)