Practical numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Drkameleon (talk | contribs) (added Arturo) |
||
Line 79: | Line 79: | ||
pract 666 ⍝ Is 666 practical? |
pract 666 ⍝ Is 666 practical? |
||
1</syntaxhighlight> |
1</syntaxhighlight> |
||
=={{header|Arturo}}== |
|||
<syntaxhighlight lang="arturo">allSums: function [n][ |
|||
result: [] |
|||
current: [] |
|||
loop factors n 'd [ |
|||
current: new result |
|||
loop current 's -> |
|||
'result ++ s+d |
|||
'result ++ d |
|||
unique 'result |
|||
] |
|||
return result |
|||
] |
|||
practical?: function [n]-> |
|||
or? -> n=1 -> subset? @1..dec n allSums n |
|||
practicals: select 1..333 => practical? |
|||
print ["Found" size practicals "practical numbers between 1 and 333:"] |
|||
loop split.every: 10 practicals 'x -> |
|||
print map x 's -> pad to :string s 4 |
|||
print "" |
|||
p666: practical? 666 |
|||
print ["666" p666 ? -> "is" -> "is not" "a practical number"]</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Found 77 practical numbers between 1 and 333: |
|||
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 a practical number</pre> |
|||
=={{header|C#|CSharp}}== |
=={{header|C#|CSharp}}== |