Neighbour primes: Difference between revisions

Neighbour primes in various BASIC dialents
(Neighbour primes en Python)
(Neighbour primes in various BASIC dialents)
Line 189:
Neighbour primes 1-499: 20
</pre>
 
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
<lang BASIC256>function isPrime(v)
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 3 = 0 then return v = 3
d = 5
while d * d <= v
if v mod d = 0 then return False else d += 2
end while
return True
end function
 
print "p q pq+2"
print "------------------------"
for p = 2 to 499
if not isPrime(p) then continue for
q = p + 1
while Not isPrime(q)
q += 1
end while
if not isPrime(2 + p*q) then continue for
print p; chr(9); q; chr(9); 2+p*q
next p
end</lang>
 
==={{header|PureBasic}}===
<lang PureBasic>Procedure isPrime(v.i)
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
ElseIf v % 2 = 0 : ProcedureReturn #False
ElseIf v < 9 : ProcedureReturn #True
ElseIf v % 3 = 0 : ProcedureReturn #False
Else
Protected r = Round(Sqr(v), #PB_Round_Down)
Protected f = 5
While f <= r
If v % f = 0 Or v % (f + 2) = 0
ProcedureReturn #False
EndIf
f + 6
Wend
EndIf
ProcedureReturn #True
EndProcedure
 
OpenConsole()
PrintN("p q pq+2")
PrintN("----------------------")
For p.i = 2 To 499
If Not isPrime(p)
Continue
EndIf
q = p + 1
While Not isPrime(q)
q + 1
Wend
If Not isPrime(2 + p*q)
Continue
EndIf
PrintN(Str(p) + #TAB$ + Str(q) + #TAB$ + Str(2+p*q))
Next p
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()</lang>
 
==={{header|Yabasic}}===
<lang yabasic>sub isPrime(v)
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 3) = 0 then return v = 3 : fi
d = 5
while d * d <= v
if mod(v, d) = 0 then return False else d = d + 2 : fi
wend
return True
end sub
 
print "p q pq+2"
print "----------------------"
for p = 2 to 499
if not isPrime(p) continue
q = p + 1
while not isPrime(q)
q = q + 1
wend
if not isPrime(2 + p*q) continue
print p, chr$(9), q, chr$(9), 2+p*q
next p
end</lang>
 
 
=={{header|C#|CSharp}}==
2,122

edits