Skip to content

Commit f337378

Browse files
committed
Only output results to stdout from Raku for consistency
1 parent 3f76be5 commit f337378

30 files changed

+299
-226
lines changed

2021/day1/day1.raku

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ class RunContext {
4343

4444
method run-part(Int $part) {
4545
my $expected = $.expected«$part» // '';
46-
say "Running Day1 part $part on $!input-file expecting '$expected'";
46+
$*ERR.say: "Running Day1 part $part on $!input-file expecting '$expected'";
4747
my $solver = Day1.new(:$!input);
4848
my $start = now;
4949
my $result = $solver."solve-part$part"();
5050
my $end = now;
51-
put $result;
52-
"Part $part took %.3fms\n".printf(($end - $start) * 1000);
51+
put "part$part: $result";
52+
$*ERR.printf("Part $part took %.3fms\n", ($end - $start) * 1000);
5353
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
5454
if $expected {
5555
if $expected eq $result {
56-
say "\c[CHECK MARK] PASS with expected value '$result'";
56+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
5757
} else {
58-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
58+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
5959
}
6060
}
6161
}
@@ -72,13 +72,13 @@ sub MAIN(*@input-files) {
7272
}
7373
}
7474
$context.run-part(1);
75-
say '';
75+
$*ERR.say: '';
7676
$context.run-part(2);
7777
$exit &= all($context.passed);
7878
} else {
79-
say "EMPTY INPUT FILE: $input-file";
79+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
8080
}
81-
say '=' x 40;
81+
$*ERR.say: '=' x 40;
8282
}
8383
exit $exit ?? 0 !! 1;
8484
}

2021/day10/day10.raku

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ class RunContext {
7171
method run-part(Solver:U $part) {
7272
my $num = $part.^name.comb(/\d+/).head;
7373
my $expected = $.expected«$num» // '';
74-
say "Running Day10 part $num on $!input-file expecting '$expected'";
74+
$*ERR.say: "Running Day10 part $num on $!input-file expecting '$expected'";
7575
my $start = now;
7676
my $solver = $part.new(:$!input);
7777
my $result = $solver.solve();
7878
my $end = now;
79-
put $result;
80-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
79+
put "part$num: $result";
80+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
8181
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
8282
if $expected {
8383
if $expected eq $result {
84-
say "\c[CHECK MARK] PASS with expected value '$result'";
84+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
8585
} else {
86-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
86+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
8787
}
8888
}
8989
}
@@ -100,13 +100,13 @@ sub MAIN(*@input-files) {
100100
}
101101
}
102102
$context.run-part(Part1);
103-
say '';
103+
$*ERR.say: '';
104104
$context.run-part(Part2);
105105
$exit &= all($context.passed);
106106
} else {
107-
say "EMPTY INPUT FILE: $input-file";
107+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
108108
}
109-
say '=' x 40;
109+
$*ERR.say: '=' x 40;
110110
}
111111
exit $exit ?? 0 !! 1;
112112
}

2021/day11/day11.raku

+8-8
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ class RunContext {
8989
method run-part(Solver:U $part) {
9090
my $num = $part.^name.comb(/\d+/).head;
9191
my $expected = $.expected«$num» // '';
92-
say "Running Day11 part $num on $!input-file expecting '$expected'";
92+
$*ERR.say: "Running Day11 part $num on $!input-file expecting '$expected'";
9393
my $start = now;
9494
my $solver = $part.new(:$!input);
9595
my $result = $solver.solve();
9696
my $end = now;
97-
put $result;
98-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
97+
put "part$num: $result";
98+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
9999
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
100100
if $expected {
101101
if $expected eq $result {
102-
say "\c[CHECK MARK] PASS with expected value '$result'";
102+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
103103
} else {
104-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
104+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
105105
}
106106
}
107107
}
@@ -118,13 +118,13 @@ sub MAIN(*@input-files) {
118118
}
119119
}
120120
$context.run-part(Part1);
121-
say '';
121+
$*ERR.say: '';
122122
$context.run-part(Part2);
123123
$exit &= all($context.passed);
124124
} else {
125-
say "EMPTY INPUT FILE: $input-file";
125+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
126126
}
127-
say '=' x 40;
127+
$*ERR.say: '=' x 40;
128128
}
129129
exit $exit ?? 0 !! 1;
130130
}

2021/day12/day12.raku

+9-9
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ class RunContext {
8181
method run-part(Solver:U $part) {
8282
my $num = $part.^name.comb(/\d+/).head;
8383
my $expected = $.expected«$num» // '';
84-
say "Running Day12 part $num on $!input-file expecting '$expected'";
84+
$*ERR.say: "Running Day12 part $num on $!input-file expecting '$expected'";
8585
my $start = now;
8686
my $solver = $part.new(:$!input);
8787
my $result = $solver.solve();
8888
my $end = now;
89-
put $result;
90-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
91-
say "Memoization of {+$solver.dfsmemo} items saved {$solver.memosaved} paths";
89+
put "part$num: $result";
90+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
91+
$*ERR.say: "Memoization of {+$solver.dfsmemo} items saved {$solver.memosaved} paths";
9292
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
9393
if $expected {
9494
if $expected eq $result {
95-
say "\c[CHECK MARK] PASS with expected value '$result'";
95+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
9696
} else {
97-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
97+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
9898
}
9999
}
100100
}
@@ -111,13 +111,13 @@ sub MAIN(*@input-files) {
111111
}
112112
}
113113
$context.run-part(Part1);
114-
say '';
114+
$*ERR.say: '';
115115
$context.run-part(Part2);
116116
$exit &= all($context.passed);
117117
} else {
118-
say "EMPTY INPUT FILE: $input-file";
118+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
119119
}
120-
say '=' x 40;
120+
$*ERR.say: '=' x 40;
121121
}
122122
return $exit ?? 0 !! 1;
123123
}

2021/day13/day13.raku

+9-8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Part2 is Solver {
6666
my $maxx = $points.keys.map({split-point($_)<x>}).max;
6767
my $maxy = $points.keys.map({split-point($_)<y>}).max;
6868
join "\n", gather {
69+
take "";
6970
for 0..$maxy -> $y {
7071
take ("$_,$y" $points ?? '#' !! '.' for 0..$maxx).join;
7172
}
@@ -83,19 +84,19 @@ class RunContext {
8384
my $num = $part.^name.comb(/\d+/).head;
8485
my $expected = $.expected«$num» // '';
8586
$expected ~~ s:g/\\n/\n/;
86-
say "Running Day13 part $num on $!input-file expecting '$expected'";
87+
$*ERR.say: "Running Day13 part $num on $!input-file expecting '$expected'";
8788
my $start = now;
8889
my $solver = $part.new(:$!input);
8990
my $result = $solver.solve();
9091
my $end = now;
91-
put $result;
92-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
92+
put "part$num: $result";
93+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
9394
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
9495
if $expected {
9596
if $expected eq $result {
96-
say "\c[CHECK MARK] PASS with expected value '$result'";
97+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
9798
} else {
98-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
99+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
99100
}
100101
}
101102
}
@@ -112,13 +113,13 @@ sub MAIN(*@input-files) {
112113
}
113114
}
114115
$context.run-part(Part1);
115-
say '';
116+
$*ERR.say: '';
116117
$context.run-part(Part2);
117118
$exit &= all($context.passed);
118119
} else {
119-
say "EMPTY INPUT FILE: $input-file";
120+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
120121
}
121-
say '=' x 40;
122+
$*ERR.say: '=' x 40;
122123
}
123124
exit $exit ?? 0 !! 1;
124125
}

2021/day13/input.actual.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
part1: 666
2-
part2: .##....##.#..#..##..####.#..#.#..#.#..#\n#..#....#.#..#.#..#....#.#..#.#.#..#..#\n#.......#.####.#..#...#..####.##...#..#\n#.......#.#..#.####..#...#..#.#.#..#..#\n#..#.#..#.#..#.#..#.#....#..#.#.#..#..#\n.##...##..#..#.#..#.####.#..#.#..#..##.
2+
part2: \n.##....##.#..#..##..####.#..#.#..#.#..#\n#..#....#.#..#.#..#....#.#..#.#.#..#..#\n#.......#.####.#..#...#..####.##...#..#\n#.......#.#..#.####..#...#..#.#.#..#..#\n#..#.#..#.#..#.#..#.#....#..#.#.#..#..#\n.##...##..#..#.#..#.####.#..#.#..#..##.

2021/day13/input.example.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
part1: 17
2-
part2: #####\n#...#\n#...#\n#...#\n#####
2+
part2: \n#####\n#...#\n#...#\n#...#\n#####

2021/day14/day14.raku

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ class RunContext {
8383
method run-part(Solver:U $part) {
8484
my $num = $part.^name.comb(/\d+/).head;
8585
my $expected = $.expected«$num» // '';
86-
say "Running Day14 part $num on $!input-file expecting '$expected'";
86+
$*ERR.say: "Running Day14 part $num on $!input-file expecting '$expected'";
8787
my $start = now;
8888
my $solver = $part.new(:$!input);
8989
my $result = $solver.solve();
9090
my $end = now;
91-
put $result;
92-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
91+
put "part$num: $result";
92+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
9393
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
9494
if $expected {
9595
if $expected eq $result {
96-
say "\c[CHECK MARK] PASS with expected value '$result'";
96+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
9797
} else {
98-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
98+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
9999
}
100100
}
101101
}
@@ -112,13 +112,13 @@ sub MAIN(*@input-files) {
112112
}
113113
}
114114
$context.run-part(Part1);
115-
say '';
115+
$*ERR.say: '';
116116
$context.run-part(Part2);
117117
$exit &= all($context.passed);
118118
} else {
119-
say "EMPTY INPUT FILE: $input-file";
119+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
120120
}
121-
say '=' x 40;
121+
$*ERR.say: '=' x 40;
122122
}
123123
exit $exit ?? 0 !! 1;
124124
}

2021/day15/day15.raku

+10-10
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Solver {
7676
while ?@options {
7777
$min++ until @options[$min];
7878
my $cur = @options[$min].pop;
79-
say "Investigating ($cur), cost $min";
79+
$*ERR.say: "Investigating ($cur), cost $min";
8080
return $_ if $_ <given %cost{$cur[0]}.sum;
8181
# say "Neighbors for $cur";
8282
# return $min if $cur == $.target;
@@ -239,21 +239,21 @@ class RunContext {
239239
method run-part(Solver:U $part) {
240240
my $num = $part.^name.comb(/\d+/).head;
241241
my $expected = $.expected«$num» // '';
242-
say "Running Day15 part $num with $!algorithm on $!input-file expecting '$expected'";
242+
$*ERR.say: "Running Day15 part $num with $!algorithm on $!input-file expecting '$expected'";
243243
my $start = now;
244244
my $solver = $part.new(:$!input, :$!algorithm);
245245
my $make-time = now;
246246
my $result = $solver.solve();
247247
my $end = now;
248-
put $result;
249-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
250-
"Construction took %.3fms solve took %.3fms\n".printf(($make-time - $start) * 1000, ($end - $make-time) * 1000);
248+
put "part$num: $result";
249+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
250+
$*ERR.printf("Construction took %.3fms solve took %.3fms\n", ($make-time - $start) * 1000, ($end - $make-time) * 1000);
251251
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
252252
if $expected {
253253
if $expected eq $result {
254-
say "\c[CHECK MARK] PASS with expected value '$result'";
254+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
255255
} else {
256-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
256+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
257257
}
258258
}
259259
}
@@ -270,13 +270,13 @@ sub MAIN(*@input-files, :$algorithm = "dijkstra") {
270270
}
271271
}
272272
$context.run-part(Part1);
273-
say '';
273+
$*ERR.say: '';
274274
$context.run-part(Part2);
275275
$exit &= all($context.passed);
276276
} else {
277-
say "EMPTY INPUT FILE: $input-file";
277+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
278278
}
279-
say '=' x 40;
279+
$*ERR.say: '=' x 40;
280280
}
281281
exit $exit ?? 0 !! 1;
282282
}

2021/day16/day16.raku

+8-8
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ class RunContext {
101101
method run-part(Solver:U $part) {
102102
my $num = $part.^name.comb(/\d+/).head;
103103
my $expected = $.expected«$num» // '';
104-
say "Running Day16 part $num on $!input-file expecting '$expected'";
104+
$*ERR.say: "Running Day16 part $num on $!input-file expecting '$expected'";
105105
my $start = now;
106106
my $solver = $part.new(:$!input);
107107
my $result = $solver.solve();
108108
my $end = now;
109-
put $result;
110-
"Part $num took %.3fms\n".printf(($end - $start) * 1000);
109+
put "part$num: $result";
110+
$*ERR.printf("Part $num took %.3fms\n", ($end - $start) * 1000);
111111
@!passed.push($result eq 'TODO' || $expected && $expected eq $result);
112112
if $expected {
113113
if $expected eq $result {
114-
say "\c[CHECK MARK] PASS with expected value '$result'";
114+
$*ERR.say: "\c[CHECK MARK] PASS with expected value '$result'";
115115
} else {
116-
say "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
116+
$*ERR.say: "\c[CROSS MARK] FAIL expected '$expected' but got '$result'";
117117
}
118118
}
119119
}
@@ -130,13 +130,13 @@ sub MAIN(*@input-files) {
130130
}
131131
}
132132
$context.run-part(Part1);
133-
say '';
133+
$*ERR.say: '';
134134
$context.run-part(Part2);
135135
$exit &= all($context.passed);
136136
} else {
137-
say "EMPTY INPUT FILE: $input-file";
137+
$*ERR.say: "EMPTY INPUT FILE: $input-file";
138138
}
139-
say '=' x 40;
139+
$*ERR.say: '=' x 40;
140140
}
141141
exit $exit ?? 0 !! 1;
142142
}

0 commit comments

Comments
 (0)