Almost prime: Difference between revisions

Content added Content deleted
(→‎Insitux: implementation by FordArthur)
imported>Chinhouse
No edit summary
Line 3,236: Line 3,236:
</pre>
</pre>


=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
primeFactory = function(n=2)
if n < 2 then return ""
for i in range(2, n)
p = floor(n / i)
q = n % i
if not q then return str(i) + " " + str(primeFactory(p))
end for
return n
end function

getAlmostPrimes = function(k)
almost = []
n = 2
while almost.len < 10
primes = primeFactory(n).trim.split
if primes.len == k then almost.push(n)
n += 1
end while
return almost
end function

for i in range(1, 5)
print i + ": " + getAlmostPrimes(i)
end for
</syntaxhighlight>

{{out}}
<pre>
]run
1: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
2: [4, 6, 9, 10, 14, 15, 21, 22, 25, 26]
3: [8, 12, 18, 20, 27, 28, 30, 42, 44, 45]
4: [16, 24, 36, 40, 54, 56, 60, 81, 84, 88]
5: [32, 48, 72, 80, 108, 112, 120, 162, 168, 176]
</pre>
=={{header|Modula-2}}==
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE AlmostPrime;
<syntaxhighlight lang="modula2">MODULE AlmostPrime;