Skip to content

Commit df4b05f

Browse files
committed
Fix some tests to work post-GLR
1 parent beaaa98 commit df4b05f

12 files changed

+53
-58
lines changed

categories/99-problems/P26-topo.pl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
=head1 Example
1010
1111
> say c(2, <a b c d e>);
12-
a b a c a d b c b d c d
12+
((a b) (a c) (a d) (a e) (b c) (b d) (b e) (c d) (c e) (d e))
1313
1414
=end pod
1515

16-
sub c(Int $n, [ $x, *@xs ])
17-
{
18-
if $n == 0 { return [] }
19-
if @xs ~~ () { return () }
20-
21-
map({ [ $x, @^others ] }, c($n - 1, @xs)), c($n, @xs);
16+
multi sub c(0, @xs) { return ((),) }
17+
multi sub c(Int $n, []) { return () }
18+
multi sub c(Int $n, [ $x, *@xs ]) {
19+
|map({($x, |@$_)}, c($n - 1, @xs)), |c($n, @xs);
2220
}
2321

24-
say c(3, <a b c d e f g h i j k l>);
22+
my @combos = c(3, <a b c d e f g h i j k l>);
23+
say @combos.elems;
24+
say @combos[200..*];
2525

2626
# vim: expandtab shiftwidth=4 ft=perl6

categories/99-problems/P91-edpratomo.pl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ =head1 Specification
3030
sub valid_moves($curr, @temp_track=@track) {
3131
my @valid_squares = @directions.map(->$a,$b { ($curr.key + $a) => ($curr.value + $b) }).grep({0 <= all(.key, .value) < $n});
3232
# exclude occupied squares. !eqv doesn't work yet.
33-
@valid_squares.grep({ not $_ eqv any(@temp_track, $curr) });
33+
@valid_squares.grep({ not $_ eqv any(|@temp_track, $curr) });
3434
}
3535

3636
sub knight($square) {
@@ -39,7 +39,9 @@ ($square)
3939

4040
# simple heuristic, for move ordering
4141
my @possible_moves = valid_moves($square).sort: ->$a,$b {
42-
valid_moves($a, [@track,$a]).elems <=> valid_moves($b, [@track, $b]).elems;
42+
valid_moves($a, [|@track,$a]).elems <=> valid_moves($b, [|@track, $b]).elems
43+
or $a.key <=> $b.key
44+
or $a.value <=> $b.value;
4345
};
4446

4547
return unless @possible_moves.elems;

categories/best-of-rosettacode/create-a-two-dimensional-array-at-runtime.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ =head1 More
2626

2727
@array[ (^$major).pick ][ (^$minor).pick ] = ' ';
2828

29-
.say for @array;
29+
.Str.say for @array;
3030

3131

3232
# vim: expandtab shiftwidth=4 ft=perl6

categories/euler/prob009-gerdr-feeds.pl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838
==> map -> @triple { [*] @triple } \
3939

4040
# ... to give the result.
41-
# We don't .say directly on the output yet, since Rakudo (2015.02) doesn't
42-
# yet handle this case of a feed into a .say
43-
==> $result;
44-
45-
# print result
46-
$result.[0].say;
41+
# XXX Rakudo feed operator wraps results in an extra sequence, thus .[0]
42+
==> { .[0].say }();
4743

4844
# vim: expandtab shiftwidth=4 ft=perl6

categories/euler/prob010-polettix.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sub primes_iterator {
4444
while $prime < $upper_bound {
4545
$sum += $prime;
4646
if $prime > $feedback_threshold {
47-
say "Processed up to prime number: $prime";
47+
say "# Processed up to prime number: $prime";
4848
$feedback_threshold += 10000;
4949
}
5050
$prime = $it();

categories/euler/prob053-gerdr.pl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@
2525
2626
=end pod
2727

28-
my @result;
29-
3028
$[1], -> @p { $[0, |@p Z+ |@p, 0] } ... * \ # generate Pascal's triangle
3129
==> (*[0..100])() \
32-
==> map *.list \
30+
==> map *.Slip \
3331
==> grep * > 1_000_000 \
3432
==> elems() \
35-
==> @result; # work around .say not yet handling feeds in Rakudo 2015.02
36-
#==> say;
37-
@result[0].say;
33+
==> (*.say)()
3834

3935
# vim: expandtab shiftwidth=4 ft=perl6

categories/euler/prob059-andreoss.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ sub infix:<XOR>(@cipher, @password) {
9494

9595
unless $pass {
9696
my %variants = guess-password $word, @cipher;
97-
$pass = %variants.max(*.value).key;
97+
$pass = %variants.pairs.max(*.value).key;
9898
say "The password is more likely to be '$pass'. " if $verbose;
9999
}
100100

categories/euler/prob081-moritz.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
my $matrix-file = $*SPEC.catdir($*PROGRAM-NAME.IO.dirname, 'matrix.txt');
3030
my $f = open $matrix-file or die "Can't open file for reading: $!";
31-
for $f.lines <-> $line {
31+
for $f.lines -> $line {
3232
@m.push: $line.comb(/\d+/).Array.item;
3333
}
3434
$f.close;

categories/euler/prob098-andreoss.pl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ (@x)
4545
%result{@v[0].chars}.push:
4646
+@v == 2
4747
?? @v.item
48-
!! @v.combinations(2).map(*.item);
48+
!! |@v.combinations(2).map(*.item);
4949
}
5050

5151
%result;
@@ -61,17 +61,16 @@ (@x)
6161

6262
my %words = anagrams(@words);
6363
my $longest-word = %words.keys.max;
64-
64+
6565
my %squares = anagrams(
66-
(1 ... (10**($longest-word + 1).sqrt)).list »**» 2
66+
(1 ... (10**($longest-word + 1).sqrt)) »**» 2
6767
);
6868

69-
7069
say max do for 3 ... $longest-word -> \size {
7170
next unless %words{size};
72-
do for @(%words{size}) -> @pair {
71+
|do for @(%words{size}) -> @pair {
7372
next unless %squares{size};
74-
do for @(%squares{size}) -> @nums {
73+
|do for @(%squares{size}) -> @nums {
7574
if correspond(@pair, @nums) {
7675
$verbose and say "@pair[] => @nums[]" ;
7776
max @nums;

t/categories/99-problems.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ for @script-names -> $name {
3434
}
3535
}
3636

37-
done;
37+
done-testing;
3838

3939
#| return hash of expected output for each example script
4040
sub expected-output {
@@ -298,7 +298,8 @@ sub expected-output {
298298
END
299299

300300
%expected-output{"P26-topo.pl"} = q:to/END/;
301-
a b c a b d a b e a b f a b g a b h a b i a b j a b k a c d a c e a c f a c g a c h a c i a c j a c k a d e a d f a d g a d h a d i a d j a d k a e f a e g a e h a e i a e j a e k a f g a f h a f i a f j a f k a g h a g i a g j a g k a h i a h j a h k a i j a i k a j k b c d b c e b c f b c g b c h b c i b c j b c k b d e b d f b d g b d h b d i b d j b d k b e f b e g b e h b e i b e j b e k b f g b f h b f i b f j b f k b g h b g i b g j b g k b h i b h j b h k b i j b i k b j k c d e c d f c d g c d h c d i c d j c d k c e f c e g c e h c e i c e j c e k c f g c f h c f i c f j c f k c g h c g i c g j c g k c h i c h j c h k c i j c i k c j k d e f d e g d e h d e i d e j d e k d f g d f h d f i d f j d f k d g h d g i d g j d g k d h i d h j d h k d i j d i k d j k e f g e f h e f i e f j e f k e g h e g i e g j e g k e h i e h j e h k e i j e i k e j k f g h f g i f g j f g k f h i f h j f h k f i j f i k f j k g h i g h j g h k g i j g i k g j k h i j h i k h j k i j k
301+
220
302+
((g h i) (g h j) (g h k) (g h l) (g i j) (g i k) (g i l) (g j k) (g j l) (g k l) (h i j) (h i k) (h i l) (h j k) (h j l) (h k l) (i j k) (i j l) (i k l) (j k l))
302303
END
303304

304305
%expected-output{"P31-rhebus.pl"} = q:to/END/;
@@ -609,7 +610,7 @@ sub expected-output {
609610
END
610611

611612
%expected-output{"P91-edpratomo.pl"} = q:to/END/;
612-
FOUND: [0 => 0, 1 => 2, 0 => 4, 2 => 3, 4 => 4, 3 => 2, 4 => 0, 2 => 1, 3 => 3, 4 => 1, 2 => 0, 0 => 1, 1 => 3, 3 => 4, 4 => 2, 3 => 0, 1 => 1, 0 => 3, 2 => 4, 4 => 3, 3 => 1, 1 => 0, 0 => 2, 1 => 4, 2 => 2]
613+
FOUND: [0 => 0, 1 => 2, 0 => 4, 2 => 3, 4 => 4, 3 => 2, 4 => 0, 2 => 1, 0 => 2, 1 => 0, 3 => 1, 4 => 3, 2 => 4, 0 => 3, 1 => 1, 3 => 0, 4 => 2, 3 => 4, 1 => 3, 0 => 1, 2 => 0, 4 => 1, 2 => 2, 1 => 4, 3 => 3]
613614
END
614615

615616
return %expected-output;

0 commit comments

Comments
 (0)