Pairs with common factors: Difference between revisions

Content added Content deleted
m (extend stretch goal)
m (→‎{{header|Raku}}: if we aren't reifying, pointless to have the intermediates)
Line 56: Line 56:


sub pair-count (\n) { n × (n - 1) / 2 + 1 - sum (1..n).map: { 𝜑[$_] } }
sub pair-count (\n) { n × (n - 1) / 2 + 1 - sum (1..n).map: { 𝜑[$_] } }

my @pairs-with-common-factors = (1..*).map: &pair-count;


say "Number of pairs with common factors - first one hundred terms:\n"
say "Number of pairs with common factors - first one hundred terms:\n"
~ @pairs-with-common-factors[^100].batch(10)».&comma».fmt("%6s").join("\n") ~ "\n";
~ (1..100).map(&pair-count).batch(10)».&comma».fmt("%6s").join("\n") ~ "\n";


for ^7 { say (my $i = 10 ** $_).&ordinal.tc.fmt("%22s term: ") ~ $i.&pair-count.&comma }</lang>
for ^7 { say (my $i = 10 ** $_).&ordinal.tc.fmt("%22s term: ") ~ $i.&pair-count.&comma }</lang>