diff options
author | Matias Linares <matias@deprecated.org> | 2024-12-04 08:54:24 -0300 |
---|---|---|
committer | Matias Linares <matias@deprecated.org> | 2024-12-04 08:54:24 -0300 |
commit | 78be8a52124f44f09cb3582cefdf736301a78a50 (patch) | |
tree | 490e7b522b63b4cfbf37bbd735c4c1aaabeab4a3 /2024 | |
parent | 789d38b8594cf73a8f6ed306b8ed90529f9c1210 (diff) | |
download | advent-of-code-78be8a52124f44f09cb3582cefdf736301a78a50.tar.gz |
Add day04
Diffstat (limited to '2024')
-rw-r--r-- | 2024/aoc-utils.scm | 4 | ||||
-rwxr-xr-x | 2024/day04/main.scm | 65 |
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) |