diff options
| author | Juan Marín Noguera <juan@mnpi.eu> | 2024-12-03 19:53:12 +0100 |
|---|---|---|
| committer | Juan Marín Noguera <juan@mnpi.eu> | 2024-12-03 19:53:42 +0100 |
| commit | 1f393d95c1c8f6793826f05660f575fee2ebe987 (patch) | |
| tree | 390bc29df28013da0628181b7f64d68ad4c1c91e /main.scm | |
| parent | 07691021e215b598d986a1709b3b6a6e0a1a031d (diff) | |
Started switch to Guile Scheme
I want to learn it more than I want to learn Lua right now.
And I won't have time for both once the problems are more difficult.
Diffstat (limited to 'main.scm')
| -rw-r--r-- | main.scm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/main.scm b/main.scm new file mode 100644 index 0000000..bcbadda --- /dev/null +++ b/main.scm @@ -0,0 +1,32 @@ +(use-modules (ice-9 format) (ice-9 regex)) + +(define args (program-arguments)) + +(unless (<= 2 (length args) 3) + (error (format #f "Syntax: ~a <DAY><a|b> [INFILE]\n")) + (exit 1)) + +(define mtch (string-match "^([0-9]+)(a|b)$" (list-ref args 1))) + +(unless mtch + (error (format #f "Expected day and part (like \"03a\" or \"02b\"), got: ~a" + (list-ref args 1)))) + +(define day (format #f "~2,'0d" (string->number (match:substring mtch 1)))) +(define part (if (string= (match:substring mtch 2) "a") 'part1 'part2)) + +(set! %load-path (cons "." %load-path)) + +(define day-module + (resolve-module (list (string->symbol (string-append "day" day))))) +(define func (module-ref day-module part)) + +(define input-file + (cond ((= (length args) 2) (string-append day ".in")) + ((string= (list-ref args 2) "-") #f) + (else (list-ref args 2)))) + +(display (if input-file + (call-with-input-file input-file func) + (func (current-input-port)))) +(newline) |
