Prime decomposition: Difference between revisions

Content added Content deleted
m (→‎{{header|Tiny BASIC}}: Works with (Tom Pittman's) TinyBasic.)
(→‎E: Add EasyLang)
Line 1,863: Line 1,863:
return factors
return factors
}</syntaxhighlight>
}</syntaxhighlight>

=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func isPrime num . result$ .
if num < 2
result$ = "false"
break 1
.
if num mod 2 = 0 and num > 2
result$ = "false"
break 1
.
for i = 3 to sqrt num
if num mod i = 0
result$ = "false"
break 2
.
.
result$ = "true"
.
func decompose num . primes[] .
# If the number is prime, return the number itself
call isPrime num result$
if result$ = "true"
primes[] &= num
break 1
.
currentPrime = 2
currentNum = num
repeat
if currentNum mod currentPrime = 0
primes[] &= currentPrime
currentNum = currentNum / currentPrime
else
repeat
currentPrime += 1
call isPrime currentPrime result$
until result$ = "true"
.
.
call isPrime currentNum result$
until result$ = "true"
.
primes[] &= currentNum
.
</syntaxhighlight>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==