Practical numbers: Difference between revisions
Content added Content deleted
m (→{{Header|Python}}: Typing ...) |
Thundergnat (talk | contribs) (→{{Header|Raku}}: Add a Raku example) |
||
Line 81: | Line 81: | ||
STRETCH GOAL: 666 is Practical.</pre> |
STRETCH GOAL: 666 is Practical.</pre> |
||
=={{header|Raku}}== |
|||
<lang perl6>use Prime::Factor:ver<0.3.0+>; |
|||
sub is-practical ($n) { |
|||
my @proper = $n.&proper-divisors.combinations».sum.unique.sort; |
|||
+@proper < $n-1 ?? False !! @proper[^$n] eqv (^$n).list ?? True !! False |
|||
} |
|||
say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}" |
|||
given [ (1..333).hyper(:32batch).grep: { is-practical($_) } ]; |
|||
say "\n666 is practical? ", is-practical 666;</lang> |
|||
{{out}} |
|||
<pre>77 matching numbers: |
|||
1 2 4 6 8 12 16 18 20 24 |
|||
28 30 32 36 40 42 48 54 56 60 |
|||
64 66 72 78 80 84 88 90 96 100 |
|||
104 108 112 120 126 128 132 140 144 150 |
|||
156 160 162 168 176 180 192 196 198 200 |
|||
204 208 210 216 220 224 228 234 240 252 |
|||
256 260 264 270 272 276 280 288 294 300 |
|||
304 306 308 312 320 324 330 |
|||
666 is practical? True</pre> |