2021-12-01 07:39:14 +00:00
|
|
|
module util.fileutils;
|
|
|
|
|
|
|
|
import std.file;
|
|
|
|
import std.string;
|
|
|
|
import std.algorithm;
|
|
|
|
import std.array;
|
|
|
|
import std.conv;
|
|
|
|
|
2021-12-02 13:45:36 +00:00
|
|
|
/**
|
|
|
|
* Reads a list of integers from a file, assuming one integer per line.
|
|
|
|
* Params:
|
|
|
|
* filename = The name of the file to read, relative to the working dir.
|
|
|
|
* Returns: A list of integers.
|
|
|
|
*/
|
2021-12-01 07:39:14 +00:00
|
|
|
int[] readInts(string filename) {
|
|
|
|
return readText("source/day1/input.txt")
|
|
|
|
.split("\n")
|
|
|
|
.map!(s => s.strip())
|
|
|
|
.filter!(s => s.length > 0)
|
|
|
|
.map!(s => s.to!int)
|
|
|
|
.array;
|
|
|
|
}
|