Frobenius numbers: Difference between revisions

Added Easylang
(Initial post)
(Added Easylang)
 
(4 intermediate revisions by 3 users not shown)
Line 679:
8447
9599</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
function IsPrime(N: integer): boolean;
{Optimised prime test - about 40% faster than the naive approach}
var I,Stop: integer;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (i + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
function GetNextPrime(Start: integer): integer;
{Get the next prime number after Start}
begin
repeat Inc(Start)
until IsPrime(Start);
Result:=Start;
end;
 
 
 
procedure ShowFrobeniusNumbers(Memo: TMemo);
var N,N1,FN,Cnt: integer;
begin
N:=2;
Cnt:=0;
while true do
begin
Inc(Cnt);
N1:=GetNextPrime(N);
FN:=N * N1 - N - N1;
N:=N1;
if FN>10000 then break;
Memo.Lines.Add(Format('%2d = %5d',[Cnt,FN]));
end;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
1 = 1
2 = 7
3 = 23
4 = 59
5 = 119
6 = 191
7 = 287
8 = 395
9 = 615
10 = 839
11 = 1079
12 = 1439
13 = 1679
14 = 1931
15 = 2391
16 = 3015
17 = 3479
18 = 3959
19 = 4619
20 = 5039
21 = 5615
22 = 6395
23 = 7215
24 = 8447
25 = 9599
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
fastfunc nextprim prim .
repeat
prim += 1
until isprim prim = 1
.
return prim
.
prim = 2
repeat
prim0 = prim
prim = nextprim prim
x = prim0 * prim - prim0 - prim
until x >= 10000
write x & " "
.
</syntaxhighlight>
{{out}}
<pre>
1 7 23 59 119 191 287 395 615 839 1079 1439 1679 1931 2391 3015 3479 3959 4619 5039 5615 6395 7215 8447 9599
</pre>
 
=={{header|Factor}}==
Line 1,505 ⟶ 1,622:
Found 25 Frobenius numbers
done...</pre>
 
=={{header|RPL}}==
« → max
« { } 2 OVER
'''DO'''
ROT SWAP + SWAP
DUP NEXTPRIME DUP2 * OVER - ROT -
'''UNTIL''' DUP max ≥ '''END'''
DROP2
» » ‘<span style="color:blue>FROB</span>’ STO
 
10000 <span style="color:blue>FROB</span>
{{out}}
<pre>
1: { 1 7 23 59 119 191 287 395 615 839 1079 1439 1679 1931 2391 3015 3479 3959 4619 5039 5615 6395 7215 8447 9599 }
</pre>
 
=={{header|Ruby}}==
Line 1,617 ⟶ 1,750:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var primes = Int.primeSieve(101)
Line 1,631 ⟶ 1,762:
}
System.print("Frobenius numbers under 10,000:")
Fmt.tprint("$,5d", frobenius, 9)
for (chunk in Lst.chunks(frobenius, 9)) Fmt.print("$,5d", chunk)
System.print("\n%(frobenius.count) such numbers found.")</syntaxhighlight>
 
2,008

edits