From 1f393d95c1c8f6793826f05660f575fee2ebe987 Mon Sep 17 00:00:00 2001 From: Juan MarĂ­n Noguera Date: Tue, 3 Dec 2024 19:53:12 +0100 Subject: 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. --- main.scm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 main.scm (limited to 'main.scm') 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 [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) -- cgit v1.2.3