Anti-primes: Difference between revisions
Content deleted Content added
→{{header|F_Sharp|F#}}: incorrect. Fix or leave the note. |
→{{header|Kotlin}}: added Lua section |
||
Line 543: | Line 543: | ||
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 |
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 |
||
</pre> |
</pre> |
||
=={{header|Lua}}== |
|||
<lang lua>-- First 20 antiprimes. |
|||
function count_factors(number) |
|||
local count = 0 |
|||
for attempt = 1, number do |
|||
local remainder = number % attempt |
|||
if remainder == 0 then |
|||
count = count + 1 |
|||
end |
|||
end |
|||
return count |
|||
end |
|||
function antiprimes(goal) |
|||
local list, number, mostFactors = {}, 1, 0 |
|||
while #list < goal do |
|||
local factors = count_factors(number) |
|||
if factors > mostFactors then |
|||
table.insert(list, number) |
|||
mostFactors = factors |
|||
end |
|||
number = number + 1 |
|||
end |
|||
return list |
|||
end |
|||
function recite(list) |
|||
for index, item in ipairs(list) do |
|||
print(item) |
|||
end |
|||
end |
|||
print("The first 20 antiprimes:") |
|||
recite(antiprimes(20)) |
|||
print("Done.") |
|||
</lang> |
|||
{{output}} |
|||
<pre>The first 20 antiprimes: |
|||
1 |
|||
2 |
|||
4 |
|||
6 |
|||
12 |
|||
24 |
|||
36 |
|||
48 |
|||
60 |
|||
120 |
|||
180 |
|||
240 |
|||
360 |
|||
720 |
|||
840 |
|||
1260 |
|||
1680 |
|||
2520 |
|||
5040 |
|||
7560 |
|||
Done.</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |