Practical numbers: Difference between revisions

m
→‎{{header|Raku}}: Better variable name, stretchy
(→‎{{Header|Raku}}: Add a Raku example)
m (→‎{{header|Raku}}: Better variable name, stretchy)
Line 86:
 
sub is-practical ($n) {
my @proper-sums = $n.&proper-divisors.combinations».sum.unique.sort;
+@proper-sums < $n-1 ?? False !! @proper-sums[^$n] eqv (^$n).list ?? True !! False
}
 
say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}\n"
given [ (1..333).hyper(:32batch).grep: { is-practical($_) } ];
 
say "\n666 666 is practical? ", is-practical 666;</lang>
say " 6666 is practical? ", is-practical 6666;
say "66666 is practical? ", is-practical 66666;</lang>
{{out}}
<pre>77 matching numbers:
Line 105 ⟶ 107:
304 306 308 312 320 324 330
 
666 is practical? True</pre>
6666 is practical? True
66666 is practical? False</pre>
10,333

edits