-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.d
More file actions
executable file
·58 lines (48 loc) · 1.45 KB
/
build.d
File metadata and controls
executable file
·58 lines (48 loc) · 1.45 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env rdmd
import std.stdio;
import std.file;
import std.process;
import std.array;
import std.algorithm;
import std.typecons;
import std.format;
import std.string;
import std.conv : to;
int main(string[] args)
{
auto executor = delegate(Tuple!(string,"day", string, "part") day, bool example) {
auto exec = executeShell(
(example)
? format!"cat day%1$s/day%1$s_%2$s.in.example | ./day%1$s/day%1$s_%2$s.d"(day.day, day.part)
: format!"cat day%1$s/day%1$s_%2$s.in | ./day%1$s/day%1$s_%2$s.d"(day.day, day.part)
);
if(exec.status != 0)
stderr.writefln("Error on day %s part %s", day.day, day.part);
return exec;
};
auto days = dirEntries("","*.d",SpanMode.depth)
.filter!(d => d.name != "build.d")
.map!`a.name.split("/").back`
.array.sort
.map!((d) {
auto signature = d.split("day")[1].split(".")[0];
auto day = signature.split("_")[0];
auto part = signature.split("_")[1];
return tuple!("day", "part")(day, part);
});
if(args[1..$].length)
{
if(args[1..$].length != 3)
return 1;
auto exec = executor(tuple!("day", "part")(args[1], args[2]), args[3].to!bool);
exec.output.write;
return 0;
}
foreach(d; days)
{
Tuple!(int,"status",string,"output") exec;
if((exec = executor(d, false)).status == 0) writefln("Day %s Part %s:\n%s", d.day, d.part, exec.output.chomp);
if((exec = executor(d, true)).status == 0) writefln("Day %s Part %s (example):\n%s", d.day, d.part, exec.output.chomp);
}
return 0;
}