Practical numbers: Difference between revisions

Added 11l
(add freebasic)
(Added 11l)
Line 18:
* Show if 666 is a Practical number
 
 
=={{header|11l}}==
{{trans|Nim}}
 
<lang 11l>F properDivisors(n)
V result = [1]
L(i) 2 .. Int(sqrt(n))
I n % i == 0
V j = n I/ i
result.append(i)
I i != j
result.append(j)
R result
 
F allSums(n)
V divs = properDivisors(n)
V currSet = Set[Int]()
V result = Set[Int]()
L(d) divs
currSet = copy(result)
L(sum) currSet
result.add(sum + d)
result.add(d)
R result
 
F isPractical(n)
R Set(Array(1 .< n)) <= allSums(n)
 
V count = 0
L(n) 1..333
I isPractical(n)
count++
print(‘#3’.format(n), end' I count % 11 == 0 {"\n"} E ‘ ’)
print(‘Found ’count‘ practical numbers between 1 and 333.’)
print()
print(‘666 is ’(I isPractical(666) {‘’} E ‘not ’)‘a practical number.’)</lang>
 
{{out}}
<pre>
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
Found 77 practical numbers between 1 and 333.
 
666 is a practical number.
</pre>
 
=={{header|APL}}==
Line 29 ⟶ 79:
pract 666 ⍝ Is 666 practical?
1</lang>
 
=={{header|C#|CSharp}}==
<lang csharp>using System.Collections.Generic; using System.Linq; using static System.Console;
1,463

edits