blob: 84e69ab39da5886be514f73098551df05899e379 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/usr/bin/env guile
!#
(use-modules (ice-9 format) (ice-9 regex))
(set! %load-extensions (cons ".sls" %load-extensions)) ; Allow r6rs dependencies
(define args (program-arguments))
(unless (<= 2 (length args) 3)
(error (format #f "Syntax: ~a <DAY><a|b> [INFILE]\n" (car args)))
(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)
|