blob: 175c9f18153751e2fa7b909476afcc16c7ef5351 (
plain) (
blame)
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
|
#!/usr/bin/sbcl --script
(load "machine.lisp")
(defun main (filename)
(multiple-value-call #'machine:run (parse filename)))
(defun parse (filename)
(with-open-file (stream filename)
(let ((contents (make-string (file-length stream))))
(read-sequence contents stream)
(extract-numbers-from-string contents))))
(defun extract-numbers-from-string (string)
(let (numbers)
(loop do
(let* ((beg (position-if #'digit-char-p string))
(end (position-if-not #'digit-char-p string :start (or beg 0))))
(unless beg
(loop-finish))
(push (parse-integer (subseq string beg end)) numbers)
(setq string (subseq string (or end (length string))))))
(setq numbers (nreverse numbers))
(values
(coerce (cdddr numbers) 'vector)
(first numbers)
(second numbers)
(third numbers))))
(loop with output = (main "input")
for number in output
for i upfrom 1
do (format t "~d~c" number (if (= i (length output))
#\Newline #\,)))
|