blob: 98e83cdcabf9a42d2e7bb948bd90198e8e6c53fc (
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
|
(define-module (aoc-utils)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (ice-9 regex)
#:use-module (ice-9 rdelim)
#:export (file->list
lines->number-list))
(define (file->list filename)
(let ((lines (string-split (call-with-input-file filename read-string) #\Newline)))
; Remove EOF token
(take lines (1- (length lines)))))
(define (lines->number-list lines)
(map (lambda (line)
(map string->number (string-split line #\Space)))
lines))
(define (remove-nth l n)
"Remove the `N' element from `L', returning a new list."
(append (list-head l n) (list-tail l (1+ n))))
(define (indexes lst)
"Get the indexes for `lst'."
(let ((retval '()))
(do ((i (1- (length lst)) (1- i)))
((< i 0))
(set! retval (cons i retval)))
retval))
|