Prime triplets: Difference between revisions

Content added Content deleted
(Added 11l)
(Prime triplets in various BASIC dialents)
Line 287: Line 287:
Prime Triplets 1-5499: 43
Prime Triplets 1-5499: 43
</pre>
</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

for p = 3 to 5499 step 2
if not isPrime(p+6) then continue for
if not isPrime(p+2) then continue for
if not isPrime(p) then continue for
print "["; p; " "; p+2; " "; p+6; "]"
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()
For p.i = 3 To 5499 Step 2
If Not isPrime(p+6)
Continue
EndIf
If Not isPrime(p+2)
Continue
EndIf
If Not isPrime(p)
Continue
EndIf
PrintN("["+ Str(p) + " " + Str(p+2) + " " + Str(p+6) + "]")
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

for p = 3 to 5499 step 2
if not isPrime(p+6) continue
if not isPrime(p+2) continue
if not isPrime(p) continue
print "[", p using "####", p+2 using "####", p+6 using "####", "]"
next p
end</lang>



=={{header|Factor}}==
=={{header|Factor}}==