Equal prime and composite sums: Difference between revisions
Added various BASIC dialects (BASIC256, Gambas, PureBasic and Yabasic) Moved FreeBASIC to section BASIC
(Added Quackery.) |
(Added various BASIC dialects (BASIC256, Gambas, PureBasic and Yabasic) Moved FreeBASIC to section BASIC) |
||
Line 31:
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">#include "isprime.kbs"
i = 0
IndN = 1 : IndM = 1
NumP = 2 : NumC = 4
SumP = 2 : SumC = 4
print " sum prime sum composite sum"
while True
if SumC > SumP then
do
NumP += 1
until isPrime(NumP)
SumP += NumP
IndN += 1
end if
if SumP > SumC then
do
NumC += 1
until not isPrime(NumC)
SumC += NumC
IndM += 1
end if
if SumP = SumC then
print rjust(string(SumP),9); " - "; rjust(string(IndN),8); " - ";rjust(string(IndM),8)
i += 1
if i >= 7 then exit while #valor mayor tarda MUUCHO
do
NumC += 1
until not isPrime(NumC)
SumC += NumC
IndM += 1
end if
end while</syntaxhighlight>
==={{header|FreeBASIC}}===
{{trans|XPL0}}
<syntaxhighlight lang="vb">#include "isprime.bas"
Dim As Integer i = 0
Dim As Integer IndN = 1, IndM = 1
Dim As Integer NumP = 2, NumC = 4
Dim As Integer SumP = 2, SumC = 4
Print " sum prime sum composite sum"
Do
If SumC > SumP Then
Do
NumP += 1
Loop Until isPrime(NumP)
SumP += NumP
IndN += 1
End If
If SumP > SumC Then
Do
NumC += 1
Loop Until Not isPrime(NumC)
SumC += NumC
IndM += 1
End If
If SumP = SumC Then
Print Using "##,###,###,###,### - ##,###,### - ##,###,###"; SumP; IndN; IndM
i += 1
If i >= 9 Then Exit Do
Do
NumC += 1
Loop Until Not isPrime(NumC)
SumC += NumC
IndM += 1
End If
Loop</syntaxhighlight>
{{out}}
<pre> sum prime sum composite sum
10 - 3 - 2
1,988 - 33 - 51
14,697 - 80 - 147
83,292 - 175 - 361
1,503,397 - 660 - 1,582
18,859,052 - 2,143 - 5,699
93,952,013 - 4,556 - 12,821
89,171,409,882 - 118,785 - 403,341
9,646,383,703,961 - 1,131,142 - 4,229,425</pre>
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">'Use "isprime.bas"
Public Sub Main()
Dim i As Integer = 0
Dim IndN As Integer = 1
Dim IndM As Integer = 1
Dim NumP As Integer = 2
Dim NumC As Integer = 4
Dim SumP As Long = 2
Dim SumC As Long = 4
Print " sum prime sum composite sum"
Do
If SumC > SumP Then
Do
NumP += 1
Loop Until isPrime(NumP)
SumP += NumP
IndN += 1
End If
If SumP > SumC Then
Do
NumC += 1
Loop Until Not isPrime(NumC)
SumC += NumC
IndM += 1
End If
If SumP = SumC Then
Print Format$(Str$(SumP), "##,###,###,###,###"); " - ";
Print Format$(Str$(IndN), "##,###,###"); " - ";
Print Format$(Str$(IndM), "##,###,###")
i += 1
If i >= 9 Then Break
Do
NumC += 1
Loop Until Not isPrime(NumC)
SumC += NumC
IndM += 1
End If
Loop
End</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">;XIncludeFile "isprime.pb"
OpenConsole()
Define.d IndN, IndM, NumP, NumC, SumP, SumC
i.i = 0
IndN = 1
IndM = 1
NumP = 2
NumC = 4
SumP = 2
SumC = 4
PrintN(" sum prime sum composite sum")
While #True
If SumC > SumP:
Repeat
NumP + 1
Until isPrime(NumP)
SumP + NumP
IndN + 1
EndIf
If SumP > SumC:
Repeat
NumC + 1
Until Not isPrime(NumC)
SumC + NumC
IndM + 1
EndIf
If SumP = SumC:
PrintN(RSet(Str(SumP),14) + " - " + RSet(Str(IndN),8) + " - " + RSet(Str(IndM),8))
i + 1
If i >= 9:
Break
EndIf
Repeat
NumC + 1
Until Not isPrime(NumC)
SumC + NumC
IndM + 1
EndIf
Wend
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">//import isprime
i = 0
IndN = 1 : IndM = 1
NumP = 2 : NumC = 4
SumP = 2 : SumC = 4
print " sum prime sum composite sum"
do
if SumC > SumP then
repeat
NumP = NumP + 1
until isPrime(NumP)
SumP = SumP + NumP
IndN = IndN + 1
fi
if SumP > SumC then
repeat
NumC = NumC + 1
until not isPrime(NumC)
SumC = SumC + NumC
IndM = IndM + 1
fi
if SumP = SumC then
print SumP using ("##,###,###,###,###"), " - ", IndN using ("##,###,###"), " - ", IndM using ("##,###,###")
i = i + 1
if i >= 9 break
repeat
NumC = NumC + 1
until not isPrime(NumC)
SumC = SumC + NumC
IndM = IndM + 1
fi
loop
print
end</syntaxhighlight>
=={{header|C++}}==
Line 213 ⟶ 431:
Primes up to 390180569 at position 20840220 and composites up to 91491160 at position 86192660 sum to 3950430820867201.
</pre>
=={{header|Go}}==
|