Ramsey's theorem: Difference between revisions

Content added Content deleted
(Added Perl example)
m (→‎{{header|Perl 6}}: .Array work-around now obsolete, factored out array-size constant)
Line 946: Line 946:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{Works with|rakudo|2017.01}}
{{Works with|rakudo|2018.08}}
<lang perl6>my @a = [ 0 xx 17 ] xx 17;
<lang perl6>my $n = 17;
@a[$_;$_] = '-' for ^17;
my @a = [ 0 xx $n ] xx $n;
@a[$_;$_] = '-' for ^$n;


for flat ^17 X 1,2,4,8 -> $i, $k {
for flat ^$n X 1,2,4,8 -> $i, $k {
my $j = ($i + $k) % 17;
my $j = ($i + $k) % $n;
@a[$i;$j] = @a[$j;$i] = 1;
@a[$i;$j] = @a[$j;$i] = 1;
}
}
.say for @a;
.say for @a;


for combinations(17,4).Array -> $quartet {
for combinations($n,4) -> $quartet {
my $links = [+] $quartet.combinations(2).map: -> $i,$j { @a[$i;$j] }
my $links = [+] $quartet.combinations(2).map: -> $i,$j { @a[$i;$j] }
die "Bogus!" unless 0 < $links < 6;
die "Bogus!" unless 0 < $links < 6;