Frobenius numbers: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 24: Line 24:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F isPrime(v)
<syntaxhighlight lang="11l">F isPrime(v)
I v <= 1
I v <= 1
R 0B
R 0B
Line 53: Line 53:
L.break
L.break
print(n‘ => ’f)
print(n‘ => ’f)
pn = i</lang>
pn = i</syntaxhighlight>


{{out}}
{{out}}
Line 86: Line 86:
=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
{{libheader|Action! Sieve of Eratosthenes}}
<lang Action!>INCLUDE "H6:SIEVE.ACT"
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT"


INT FUNC NextPrime(INT p BYTE ARRAY primes)
INT FUNC NextPrime(INT p BYTE ARRAY primes)
Line 114: Line 114:
FI
FI
OD
OD
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Frobenius_numbers.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Frobenius_numbers.png Screenshot from Atari 8-bit computer]
Line 122: Line 122:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find some Frobenius Numbers: #
<syntaxhighlight lang="algol68">BEGIN # find some Frobenius Numbers: #
# Frobenius(n) = ( prime(n) * prime(n+1) ) - prime(n) - prime(n+1) #
# Frobenius(n) = ( prime(n) * prime(n+1) ) - prime(n) - prime(n+1) #
# reurns a list of primes up to n #
# reurns a list of primes up to n #
Line 150: Line 150:
print( ( " ", whole( frobenius number, 0 ) ) )
print( ( " ", whole( frobenius number, 0 ) ) )
OD
OD
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 158: Line 158:
=={{header|APL}}==
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|Dyalog APL}}
<lang APL>(¯1↓(⊢×1∘⌽)-⊢+1∘⌽)∘((⊢(/⍨)(~⊢∊∘.×⍨))1↓⍳)∘(⌊1+*∘.5) 10000</lang>
<syntaxhighlight lang="apl">(¯1↓(⊢×1∘⌽)-⊢+1∘⌽)∘((⊢(/⍨)(~⊢∊∘.×⍨))1↓⍳)∘(⌊1+*∘.5) 10000</syntaxhighlight>
{{out}}
{{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>
<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|AppleScript}}==
=={{header|AppleScript}}==
<lang applescript>on isPrime(n)
<syntaxhighlight lang="applescript">on isPrime(n)
if (n < 4) then return (n > 1)
if (n < 4) then return (n > 1)
if ((n mod 2 is 0) or (n mod 3 is 0)) then return false
if ((n mod 2 is 0) or (n mod 3 is 0)) then return false
Line 193: Line 193:
end Frobenii
end Frobenii


Frobenii(9999)</lang>
Frobenii(9999)</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>{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}</lang>
<syntaxhighlight lang="applescript">{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}</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>primes: select 0..10000 => prime?
<syntaxhighlight lang="rebol">primes: select 0..10000 => prime?
frobenius: function [n] -> sub sub primes\[n] * primes\[n+1] primes\[n] primes\[n+1]
frobenius: function [n] -> sub sub primes\[n] * primes\[n+1] primes\[n] primes\[n+1]


Line 211: Line 211:


loop split.every:10 chop lst 'a ->
loop split.every:10 chop lst 'a ->
print map a => [pad to :string & 5]</lang>
print map a => [pad to :string & 5]</syntaxhighlight>


{{out}}
{{out}}
Line 220: Line 220:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>n := 0, i := 1, pn := 2
<syntaxhighlight lang="autohotkey">n := 0, i := 1, pn := 2
loop {
loop {
if isprime(i+=2) {
if isprime(i+=2) {
Line 245: Line 245:
return false
return false
return true
return true
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 7 23 59 119
<pre> 1 7 23 59 119
Line 254: Line 254:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f FROBENIUS_NUMBERS.AWK
# syntax: GAWK -f FROBENIUS_NUMBERS.AWK
# converted from FreeBASIC
# converted from FreeBASIC
Line 283: Line 283:
return(1)
return(1)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 293: Line 293:


=={{header|BASIC}}==
=={{header|BASIC}}==
<lang basic>10 DEFINT A-Z
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 LM = 10000
20 LM = 10000
30 M = SQR(LM)+1
30 M = SQR(LM)+1
Line 305: Line 305:
110 FOR N=0 TO C-2
110 FOR N=0 TO C-2
120 PRINT P(N)*P(N+1)-P(N)-P(N+1),
120 PRINT P(N)*P(N+1)-P(N)-P(N+1),
130 NEXT N</lang>
130 NEXT N</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 7 23 59 119
<pre> 1 7 23 59 119
Line 315: Line 315:


=={{header|BASIC256}}==
=={{header|BASIC256}}==
<syntaxhighlight lang="basic256">
<lang BASIC256>
n = 0
n = 0
lim = 10000
lim = 10000
Line 334: Line 334:
next i
next i
end
end
</syntaxhighlight>
</lang>




=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"
manifest $( limit = 10000 $)
manifest $( limit = 10000 $)


Line 391: Line 391:
writef("%N*N", frob(primes, n))
writef("%N*N", frob(primes, n))
freevec(primes)
freevec(primes)
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre>1
<pre>1
Line 420: Line 420:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
#include <math.h>
Line 457: Line 457:
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1
<pre>1
Line 487: Line 487:
=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
Asterisks mark the non-primes among the numbers.
Asterisks mark the non-primes among the numbers.
<lang csharp>using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math;
<syntaxhighlight lang="csharp">using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math;


class Program {
class Program {
Line 509: Line 509:
if (!flags[j]) { yield return j;
if (!flags[j]) { yield return j;
for (int k = sq, i = j << 1; k <= lim; k += i) flags[k] = true; }
for (int k = sq, i = j << 1; k <= lim; k += i) flags[k] = true; }
for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }</lang>
for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }</syntaxhighlight>


{{out}}
{{out}}
Line 534: Line 534:
=={{header|C++}}==
=={{header|C++}}==
{{libheader|Primesieve}}
{{libheader|Primesieve}}
<lang cpp>#include <cstdint>
<syntaxhighlight lang="cpp">#include <cstdint>
#include <iomanip>
#include <iomanip>
#include <iostream>
#include <iostream>
Line 573: Line 573:
}
}
std::cout << '\n';
std::cout << '\n';
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 598: Line 598:


=={{header|Cowgol}}==
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


const LIMIT := 10000;
const LIMIT := 10000;
Line 652: Line 652:
print_nl();
print_nl();
n := n + 1;
n := n + 1;
end loop;</lang>
end loop;</syntaxhighlight>
{{out}}
{{out}}
<pre>1
<pre>1
Line 682: Line 682:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: io kernel math math.primes prettyprint ;
<syntaxhighlight lang="factor">USING: io kernel math math.primes prettyprint ;


"Frobenius numbers < 10,000:" print
"Frobenius numbers < 10,000:" print
Line 688: Line 688:
[ nip dup next-prime ] [ * ] [ [ - ] dip - ] 2tri
[ nip dup next-prime ] [ * ] [ [ - ] dip - ] 2tri
dup 10,000 <
dup 10,000 <
] [ . ] while 3drop</lang>
] [ . ] while 3drop</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:14em">
<pre style="height:14em">
Line 720: Line 720:


=={{header|Fermat}}==
=={{header|Fermat}}==
<lang fermat>Function Frobenius(n)=Prime(n)*Prime(n+1)-Prime(n)-Prime(n+1).
<syntaxhighlight lang="fermat">Function Frobenius(n)=Prime(n)*Prime(n+1)-Prime(n)-Prime(n+1).
for n = 1 to 25 do !!Frobenius(n) od</lang>
for n = 1 to 25 do !!Frobenius(n) od</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 752: Line 752:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>#include "isprime.bas"
<syntaxhighlight lang="freebasic">#include "isprime.bas"


dim as integer pn=2, n=0, f
dim as integer pn=2, n=0, f
Line 763: Line 763:
pn = i
pn = i
end if
end if
next i</lang>
next i</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 796: Line 796:
{{trans|Wren}}
{{trans|Wren}}
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 821: Line 821:
}
}
fmt.Printf("\n\n%d such numbers found.\n", len(frobenius))
fmt.Printf("\n\n%d such numbers found.\n", len(frobenius))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 834: Line 834:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>primes = 2 : sieve [3,5..]
<syntaxhighlight lang="haskell">primes = 2 : sieve [3,5..]
where sieve (x:xs) = x : sieve (filter (\y -> y `mod` x /= 0) xs)
where sieve (x:xs) = x : sieve (filter (\y -> y `mod` x /= 0) xs)


frobenius = zipWith (\a b -> a*b - a - b) primes (tail primes)</lang>
frobenius = zipWith (\a b -> a*b - a - b) primes (tail primes)</syntaxhighlight>


<pre>λ> takeWhile (< 10000) frobenius
<pre>λ> takeWhile (< 10000) frobenius
Line 843: Line 843:


=={{header|J}}==
=={{header|J}}==
<lang J>frob =: (*&p: - +&p:) >:
<syntaxhighlight lang="j">frob =: (*&p: - +&p:) >:
echo frob i. 25</lang>
echo frob i. 25</syntaxhighlight>


(Note that <code>frob</code> counts prime numbers starting from 0 (which gives 2), so for some contexts the function to calculate frobenius numbers would be <code>frob@<:</code>.)
(Note that <code>frob</code> counts prime numbers starting from 0 (which gives 2), so for some contexts the function to calculate frobenius numbers would be <code>frob@<:</code>.)
Line 853: Line 853:
=={{header|Java}}==
=={{header|Java}}==
Uses the PrimeGenerator class from [[Extensible prime generator#Java]].
Uses the PrimeGenerator class from [[Extensible prime generator#Java]].
<lang java>public class Frobenius {
<syntaxhighlight lang="java">public class Frobenius {
public static void main(String[] args) {
public static void main(String[] args) {
final int limit = 1000000;
final int limit = 1000000;
Line 888: Line 888:
return true;
return true;
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 921: Line 921:


See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
<lang jq># Generate a stream of Frobenius numbers up to an including `.`;
<syntaxhighlight lang="jq"># Generate a stream of Frobenius numbers up to an including `.`;
# specify `null` or `infinite` to generate an unbounded stream.
# specify `null` or `infinite` to generate an unbounded stream.
def frobenius:
def frobenius:
Line 934: Line 934:
.frob);
.frob);


9999 | frobenius</lang>
9999 | frobenius</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 965: Line 965:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


const primeslt10k = primes(10000)
const primeslt10k = primes(10000)
Line 989: Line 989:


testfrobenius()
testfrobenius()
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Frobenius numbers less than 1,000,000 (an asterisk marks the prime ones).
Frobenius numbers less than 1,000,000 (an asterisk marks the prime ones).
Line 1,012: Line 1,012:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[fn]
<syntaxhighlight lang="mathematica">ClearAll[fn]
fn[n_] := Prime[n] Prime[n + 1] - Prime[n] - Prime[n + 1]
fn[n_] := Prime[n] Prime[n + 1] - Prime[n] - Prime[n + 1]
a = -1;
a = -1;
Line 1,022: Line 1,022:
If[a < 10^4, AppendTo[res, a]]
If[a < 10^4, AppendTo[res, a]]
]
]
res</lang>
res</syntaxhighlight>
{{out}}
{{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>
<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>
Line 1,028: Line 1,028:
=={{header|Nim}}==
=={{header|Nim}}==
As I like iterators, I used one for (odd) primes and one for Frobenius numbers. Of course, there are other ways to proceed.
As I like iterators, I used one for (odd) primes and one for Frobenius numbers. Of course, there are other ways to proceed.
<lang Nim>import sequtils, strutils
<syntaxhighlight lang="nim">import sequtils, strutils


func isOddPrime(n: Positive): bool =
func isOddPrime(n: Positive): bool =
Line 1,060: Line 1,060:
var result = toSeq(frobenius(10_000))
var result = toSeq(frobenius(10_000))
echo "Found $1 Frobenius numbers less than $2:".format(result.len, N)
echo "Found $1 Frobenius numbers less than $2:".format(result.len, N)
echo result.join(" ")</lang>
echo result.join(" ")</syntaxhighlight>


{{out}}
{{out}}
Line 1,068: Line 1,068:
=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use feature 'say';
use feature 'say';
Line 1,081: Line 1,081:
# process a list with a 2-wide sliding window
# process a list with a 2-wide sliding window
my $limit = 10_000;
my $limit = 10_000;
say "\n" . join ' ', grep { $_ < $limit } slide { $a * $b - $a - $b } @{primes($limit)};</lang>
say "\n" . join ' ', grep { $_ < $limit } slide { $a * $b - $a - $b } @{primes($limit)};</syntaxhighlight>
{{out}}
{{out}}
<pre>25 matching numbers:
<pre>25 matching numbers:
Line 1,089: Line 1,089:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">4</span> <span style="color: #008080;">to</span> <span style="color: #000000;">6</span> <span style="color: #008080;">by</span> <span style="color: #000000;">2</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">4</span> <span style="color: #008080;">to</span> <span style="color: #000000;">6</span> <span style="color: #008080;">by</span> <span style="color: #000000;">2</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span>
Line 1,105: Line 1,105:
<span style="color: #0000FF;">{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frob</span><span style="color: #0000FF;">),</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frob</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<span style="color: #0000FF;">{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frob</span><span style="color: #0000FF;">),</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frob</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,114: Line 1,114:


=={{header|Python}}==
=={{header|Python}}==
<lang python>
<syntaxhighlight lang="python">
#!/usr/bin/python
#!/usr/bin/python


Line 1,147: Line 1,147:
print (n, ' => ', f)
print (n, ' => ', f)
pn = i
pn = i
</syntaxhighlight>
</lang>


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang plm>100H:
<syntaxhighlight lang="plm">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,223: Line 1,223:
END;
END;
CALL EXIT;
CALL EXIT;
EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>1
<pre>1
Line 1,253: Line 1,253:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">
<lang PureBasic>
Procedure isPrime(v.i)
Procedure isPrime(v.i)
If v < = 1 : ProcedureReturn #False
If v < = 1 : ProcedureReturn #False
Line 1,290: Line 1,290:
CloseConsole()
CloseConsole()
End
End
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,322: Line 1,322:


=={{header|Raku}}==
=={{header|Raku}}==
<lang perl6>say "{+$_} matching numbers\n{.batch(10)».fmt('%4d').join: "\n"}\n"
<syntaxhighlight lang="raku" line>say "{+$_} matching numbers\n{.batch(10)».fmt('%4d').join: "\n"}\n"
given (^1000).grep( *.is-prime ).rotor(2 => -1)
given (^1000).grep( *.is-prime ).rotor(2 => -1)
.map( { (.[0] * .[1] - .[0] - .[1]) } ).grep(* < 10000);</lang>
.map( { (.[0] * .[1] - .[0] - .[1]) } ).grep(* < 10000);</syntaxhighlight>
{{out}}
{{out}}
<pre>25 matching numbers
<pre>25 matching numbers
Line 1,332: Line 1,332:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program finds Frobenius numbers where the numbers are less than some number N. */
<syntaxhighlight lang="rexx">/*REXX program finds Frobenius numbers where the numbers are less than some number N. */
parse arg hi cols . /*obtain optional argument from the CL.*/
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 10000 /* " " " " " " */
if hi=='' | hi=="," then hi= 10000 /* " " " " " " */
Line 1,370: Line 1,370:
end /*k*/ /* [↑] only process numbers ≤ √ J */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; sq.#= j*j /*bump # Ps; assign next P; P squared*/
#= #+1; @.#= j; sq.#= j*j /*bump # Ps; assign next P; P squared*/
end /*j*/; return</lang>
end /*j*/; return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 1,384: Line 1,384:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>load "stdlib.ring" # for isprime() function
<syntaxhighlight lang="ring">load "stdlib.ring" # for isprime() function
? "working..." + nl + "Frobenius numbers are:"
? "working..." + nl + "Frobenius numbers are:"
Line 1,407: Line 1,407:
s = string(x) l = len(s)
s = string(x) l = len(s)
if l > y y = l ok
if l > y y = l ok
return substr(" ", 11 - y + l) + s</lang>
return substr(" ", 11 - y + l) + s</syntaxhighlight>
{{out}}
{{out}}
<pre>working...
<pre>working...
Line 1,422: Line 1,422:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>// [dependencies]
<syntaxhighlight lang="rust">// [dependencies]
// primal = "0.3"
// primal = "0.3"


Line 1,452: Line 1,452:
}
}
println!();
println!();
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,477: Line 1,477:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func frobenius_number(n) {
<syntaxhighlight lang="ruby">func frobenius_number(n) {
prime(n) * prime(n+1) - prime(n) - prime(n+1)
prime(n) * prime(n+1) - prime(n) - prime(n+1)
}
}
Line 1,487: Line 1,487:
take(n)
take(n)
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,497: Line 1,497:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/seq" for Lst
import "/seq" for Lst
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 1,510: Line 1,510:
System.print("Frobenius numbers under 10,000:")
System.print("Frobenius numbers under 10,000:")
for (chunk in Lst.chunks(frobenius, 9)) Fmt.print("$,5d", chunk)
for (chunk in Lst.chunks(frobenius, 9)) Fmt.print("$,5d", chunk)
System.print("\n%(frobenius.count) such numbers found.")</lang>
System.print("\n%(frobenius.count) such numbers found.")</syntaxhighlight>


{{out}}
{{out}}
Line 1,523: Line 1,523:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
int N, I;
[if N <= 1 then return false;
[if N <= 1 then return false;
Line 1,548: Line 1,548:
Text(0, " Frobenius numbers found below 10,000.
Text(0, " Frobenius numbers found below 10,000.
");
");
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 1,560: Line 1,560:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
{{trans|PureBasic}}
{{trans|PureBasic}}
<lang yabasic>
<syntaxhighlight lang="yabasic">
sub isPrime(v)
sub isPrime(v)
if v < 2 then return False : fi
if v < 2 then return False : fi
Line 1,584: Line 1,584:
next i
next i
end
end
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>