Calmo numbers: Difference between revisions

Calmo numbersin various dialects BASIC (BASIC256, FreeBASIC, Run BASIC and Yabasic)
m (→‎{{header|Go}}: Added previously omitted first line of output.)
(Calmo numbersin various dialects BASIC (BASIC256, FreeBASIC, Run BASIC and Yabasic))
Line 78:
165 273 385 399 561 595 665 715 957
</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="vb">include "isprime.kbs"
 
for n = 1 to 1000-1
if isCalmo(n) then print n; " ";
next n
end
 
function isCalmo(n)
limite = sqr(n)
cont = 0: SumD = 0: SumQ = 0: k = 0: q = 0
d = 2
do
q = n/d
if n mod d = 0 then
cont += 1
SumD += d
SumQ += q
if cont = 3 then
k += 3
if not IsPrime(SumD) then return False
if not IsPrime(SumQ) then return False
cont = 0: SumD = 0: SumQ = 0
end if
end if
d += 1
until d >= limite
if cont <> 0 or k = 0 then return False
return True
end function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="vb">#include "isprime.bas"
 
Function isCalmo(n As Integer) As Boolean
Dim As Integer limite = Sqr(n)
Dim As Integer cont = 0, SumD = 0, SumQ = 0, k = 0, q = 0, d = 2
Do
q = n/d
If (n Mod d) = 0 Then
cont += 1
SumD += d
SumQ += q
If cont = 3 Then
k += 3
If Not IsPrime(SumD) Orelse Not IsPrime(SumQ) Then Return False
cont = 0: SumD = 0: SumQ = 0
End If
End If
d += 1
Loop Until d >= limite
If cont <> 0 Or k = 0 Then Return False
Return True
End Function
 
For n As Integer = 1 To 1000-1
If isCalmo(n) Then Print n;
Next n
 
Sleep</syntaxhighlight>
{{out}}
<pre>165 273 385 399 561 595 665 715 957</pre>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
<syntaxhighlight lang="vb">for n = 1 to 1000-1
if isCalmo(n) then print n; " ";
next n
end
 
function isPrime(n)
if n < 2 then isPrime = 0 : goto [exit]
if n = 2 then isPrime = 1 : goto [exit]
if n mod 2 = 0 then isPrime = 0 : goto [exit]
isPrime = 1
for i = 3 to int(n^.5) step 2
if n mod i = 0 then isPrime = 0 : goto [exit]
next i
[exit]
end function
 
function isCalmo(n)
limite = sqr(n)
cont = 0: SumD = 0: SumQ = 0: k = 0: q = 0
d = 2
[start]
q = n/d
if n mod d = 0 then
cont = cont +1
SumD = SumD +d
SumQ = SumQ +q
if cont = 3 then
k = k + 3
if not(isPrime(SumD)) then isCalmo = 0 : goto [exit]
if not(isPrime(SumQ)) then isCalmo = 0 : goto [exit]
cont = 0: SumD = 0: SumQ = 0
end if
end if
d = d +1
if d < limite then [start]
if cont <> 0 or k = 0 then isCalmo = 0 : goto [exit]
isCalmo = 1
[exit]
end function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="vb">import isprime
 
for n = 1 to 1000-1
if isCalmo(n) print n, " ";
next n
print
end
 
sub isCalmo(n)
local limite, cont, SumD, SumQ, k, d, q
limite = sqrt(n)
cont = 0: SumD = 0: SumQ = 0: k = 0: q = 0: d = 2
repeat
q = n/d
if mod(n, d) = 0 then
cont = cont+1
SumD = SumD+d
SumQ = SumQ+q
if cont = 3 then
k = k+3
if not isPrime(SumD) return False
if not isPrime(SumQ) return False
cont = 0: SumD = 0: SumQ = 0
fi
fi
d = d+1
until d >= limite
if cont <> 0 or k = 0 return False
return True
end sub</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|Go}}==
2,123

edits