Practical numbers: Difference between revisions

→‎{{header|Raku}}: Do some smarter filtering. More verbose but MUCH faster for most numbers
(No Paddy, you can't endlessly delete approaches which you wish to discourage. We are optimizing different things. Live and let live. Let others show their approach.)
(→‎{{header|Raku}}: Do some smarter filtering. More verbose but MUCH faster for most numbers)
Line 620:
 
sub is-practical ($n) {
return True if $n == 1;
my @proper-sums = $n.&proper-divisors.combinations».sum.unique.sort;
return False if $n % 2;
my @proper = $n.&proper-divisors :sort;
return True if all( @proper.rotor(2 => -1).map: { .[0] / .[1] >= .5 } );
my @proper-sums = $n.&@proper-divisors.combinations».sum.unique.sort;
+@proper-sums < $n-1 ?? False !! @proper-sums[^$n] eqv (^$n).list ?? True !! False
}
Line 627 ⟶ 631:
given [ (1..333).hyper(:32batch).grep: { is-practical($_) } ];
 
printf "%5s is practical? %s\n", $_, .&is-practical for 666, 6666, 66666, 672, 720;</lang>
{{out}}
<pre>77 matching numbers:
Line 641 ⟶ 645:
666 is practical? True
6666 is practical? True
66666 is practical? False</pre>
672 is practical? True
720 is practical? True</pre>
 
=={{header|Wren}}==
10,333

edits