Erdős-primes: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19: | Line 19: | ||
{{trans|Nim}} |
{{trans|Nim}} |
||
< |
<syntaxhighlight lang="11l">F primes_upto(limit) |
||
V is_prime = [0B] * 2 [+] [1B] * (limit - 1) |
V is_prime = [0B] * 2 [+] [1B] * (limit - 1) |
||
L(n) 0 .< Int(limit ^ 0.5 + 1.5) |
L(n) 0 .< Int(limit ^ 0.5 + 1.5) |
||
Line 62: | Line 62: | ||
I count == 7875 |
I count == 7875 |
||
print("\nThe 7875th Erdos prime is "p‘.’) |
print("\nThe 7875th Erdos prime is "p‘.’) |
||
L.break</ |
L.break</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 76: | Line 76: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
{{libheader|Action! Sieve of Eratosthenes}} |
{{libheader|Action! Sieve of Eratosthenes}} |
||
< |
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT" |
||
BYTE Func IsErdosPrime(INT x BYTE ARRAY primes) |
BYTE Func IsErdosPrime(INT x BYTE ARRAY primes) |
||
Line 111: | Line 111: | ||
OD |
OD |
||
PrintF("%E%EThere are %I Erdos primes",count) |
PrintF("%E%EThere are %I Erdos primes",count) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Erd%C5%91s-primes.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Erd%C5%91s-primes.png Screenshot from Atari 8-bit computer] |
||
Line 121: | Line 121: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68">BEGIN # find Erdős primes - primes p such that p-k! is composite for all 1<=k!<p # |
||
# returns TRUE if p is an Erdős prime # |
# returns TRUE if p is an Erdős prime # |
||
PROC is erdos prime = ( INT p )BOOL: |
PROC is erdos prime = ( INT p )BOOL: |
||
Line 156: | Line 156: | ||
OD; |
OD; |
||
print( ( newline, "Found ", whole( e count, 0 ), " Erdos primes" ) ) |
print( ( newline, "Found ", whole( e count, 0 ), " Erdos primes" ) ) |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 165: | Line 165: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">factorials: map 1..20 => [product 1..&] |
||
erdos?: function [x][ |
erdos?: function [x][ |
||
if not? prime? x -> return false |
if not? prime? x -> return false |
||
Line 177: | Line 177: | ||
loop split.every:10 select 2..2500 => erdos? 'a -> |
loop split.every:10 select 2..2500 => erdos? 'a -> |
||
print map a => [pad to :string & 5]</ |
print map a => [pad to :string & 5]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 186: | Line 186: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f ERDOS-PRIMES.AWK |
# syntax: GAWK -f ERDOS-PRIMES.AWK |
||
# converted from FreeBASIC |
# converted from FreeBASIC |
||
Line 224: | Line 224: | ||
return(1) |
return(1) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 233: | Line 233: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">using System; using static System.Console; |
||
class Program { |
class Program { |
||
const int lmt = (int)1e6, first = 2500; static int[] f = new int[10]; |
const int lmt = (int)1e6, first = 2500; static int[] f = new int[10]; |
||
Line 255: | Line 255: | ||
if (x < 4) return x > 1; if ((x & 1) == 0) return false; |
if (x < 4) return x > 1; if ((x & 1) == 0) return false; |
||
for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false; |
for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false; |
||
return true; } } }</ |
return true; } } }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 2 101 211 367 409 |
<pre> 2 101 211 367 409 |
||
Line 268: | Line 268: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{libheader|Primesieve}} |
{{libheader|Primesieve}} |
||
< |
<syntaxhighlight lang="cpp">#include <cstdint> |
||
#include <iomanip> |
#include <iomanip> |
||
#include <iostream> |
#include <iostream> |
||
Line 317: | Line 317: | ||
std::wcout << L"\n\nThe " << max_count << L"th Erd\x151s prime is " << p << L".\n"; |
std::wcout << L"\n\nThe " << max_count << L"th Erd\x151s prime is " << p << L".\n"; |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 331: | Line 331: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Erdős Primes. Nigel Galloway: March 22nd., 2021 |
// Erdős Primes. Nigel Galloway: March 22nd., 2021 |
||
let rec fN g=function 1->g |n->fN(g*n)(n-1) |
let rec fN g=function 1->g |n->fN(g*n)(n-1) |
||
Line 337: | Line 337: | ||
let eP()=primes32()|>Seq.filter(fG 1>>Seq.forall id) |
let eP()=primes32()|>Seq.filter(fG 1>>Seq.forall id) |
||
eP()|>Seq.takeWhile((>)2500)|>Seq.iter(printf "%d "); printfn "\n\n7875th Erdős prime is %d" (eP()|>Seq.item 7874) |
eP()|>Seq.takeWhile((>)2500)|>Seq.iter(printf "%d "); printfn "\n\n7875th Erdős prime is %d" (eP()|>Seq.item 7874) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 346: | Line 346: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
<lang>USING: formatting io kernel lists lists.lazy math |
<syntaxhighlight lang="text">USING: formatting io kernel lists lists.lazy math |
||
math.factorials math.primes math.primes.lists math.vectors |
math.factorials math.primes math.primes.lists math.vectors |
||
prettyprint sequences tools.memory.private ; |
prettyprint sequences tools.memory.private ; |
||
Line 363: | Line 363: | ||
7874 erdős lnth commas |
7874 erdős lnth commas |
||
"The 7,875th Erdős prime is %s.\n" printf</ |
"The 7,875th Erdős prime is %s.\n" printf</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 374: | Line 374: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang="forth">: prime? ( n -- ? ) here + c@ 0= ; |
||
: notprime! ( n -- ) here + 1 swap c! ; |
: notprime! ( n -- ) here + 1 swap c! ; |
||
Line 425: | Line 425: | ||
2500 print_erdos_primes |
2500 print_erdos_primes |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 438: | Line 438: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
I won't bother reproducing a primality-testing function; use the one from [[Primality_by_trial_division#FreeBASIC]]. |
I won't bother reproducing a primality-testing function; use the one from [[Primality_by_trial_division#FreeBASIC]]. |
||
< |
<syntaxhighlight lang="freebasic">#include "isprime.bas" |
||
function is_erdos_prime( p as uinteger ) as boolean |
function is_erdos_prime( p as uinteger ) as boolean |
||
Line 457: | Line 457: | ||
if i<2500 or c=7875 then print c, i |
if i<2500 or c=7875 then print c, i |
||
end if |
end if |
||
wend</ |
wend</syntaxhighlight> |
||
{{out}}<pre>1 2 |
{{out}}<pre>1 2 |
||
2 101 |
2 101 |
||
Line 489: | Line 489: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 579: | Line 579: | ||
show := 7875 |
show := 7875 |
||
fmt.Printf("\n\nThe %s Erdős prime is %s.\n", commatize(show), commatize(erdos[show-1])) |
fmt.Printf("\n\nThe %s Erdős prime is %s.\n", commatize(show), commatize(erdos[show-1])) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 594: | Line 594: | ||
Implementation: |
Implementation: |
||
< |
<syntaxhighlight lang="j">NB. erdos primes greater than !k and less than or equal to !k+1 (where !k is the factorial of k) |
||
erdospr=: {{ k=. y |
erdospr=: {{ k=. y |
||
f=. !k+0 1 |
f=. !k+0 1 |
||
Line 602: | Line 602: | ||
NB. erdos primes less than j |
NB. erdos primes less than j |
||
erdosprs=: {{ (#~ j&>);erdospr&.>i.>.!inv j=. y }}</ |
erdosprs=: {{ (#~ j&>);erdospr&.>i.>.!inv j=. y }}</syntaxhighlight> |
||
Task examples: |
Task examples: |
||
< |
<syntaxhighlight lang="j"> erdosprs 2500 |
||
2 101 211 367 409 419 461 557 673 709 769 937 967 1009 1201 1259 1709 1831 1889 2141 2221 2309 2351 2411 2437 |
2 101 211 367 409 419 461 557 673 709 769 937 967 1009 1201 1259 1709 1831 1889 2141 2221 2309 2351 2411 2437 |
||
(#,{:) erdosprs 1e6 |
(#,{:) erdosprs 1e6 |
||
7875 999721</ |
7875 999721</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">import java.util.*; |
||
public class ErdosPrimes { |
public class ErdosPrimes { |
||
Line 665: | Line 665: | ||
return sieve; |
return sieve; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 683: | Line 683: | ||
'''Preliminaries''' |
'''Preliminaries''' |
||
< |
<syntaxhighlight lang="jq">def emit_until(cond; stream): label $out | stream | if cond then break $out else . end; |
||
def is_prime: |
def is_prime: |
||
Line 700: | Line 700: | ||
| . * . > $n |
| . * . > $n |
||
end; |
end; |
||
</syntaxhighlight> |
|||
</lang> |
|||
'''Erdős-primes''' |
'''Erdős-primes''' |
||
< |
<syntaxhighlight lang="jq"> |
||
def is_Erdos: |
def is_Erdos: |
||
. as $p |
. as $p |
||
Line 717: | Line 717: | ||
# emit the Erdos primes |
# emit the Erdos primes |
||
def Erdos: range(2; infinite) | select(is_Erdos); |
def Erdos: range(2; infinite) | select(is_Erdos); |
||
</syntaxhighlight> |
|||
</lang> |
|||
'''The tasks''' |
'''The tasks''' |
||
< |
<syntaxhighlight lang="jq">"The Erdős primes less than 2500 are:", emit_until(. >= 2500; Erdos), |
||
"\nThe 7875th Erdős prime is \(nth(7874; Erdos))." |
"\nThe 7875th Erdős prime is \(nth(7874; Erdos))." |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 756: | Line 756: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Primes, Formatting |
||
function isErdős(p::Integer) |
function isErdős(p::Integer) |
||
Line 773: | Line 773: | ||
println(length(E2500), " Erdős primes < 2500: ", E2500) |
println(length(E2500), " Erdős primes < 2500: ", E2500) |
||
println("The 7875th Erdős prime is ", format(Erdőslist[7875], commas=true)) |
println("The 7875th Erdős prime is ", format(Erdőslist[7875], commas=true)) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
25 Erdős primes < 2500: [2, 101, 211, 367, 409, 419, 461, 557, 673, 709, 769, 937, 967, 1009, 1201, 1259, 1709, 1831, 1889, 2141, 2221, 2309, 2351, 2411, 2437] |
25 Erdős primes < 2500: [2, 101, 211, 367, 409, 419, 461, 557, 673, 709, 769, 937, 967, 1009, 1201, 1259, 1709, 1831, 1889, 2141, 2221, 2309, 2351, 2411, 2437] |
||
Line 780: | Line 780: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[ErdosPrimeQ] |
||
ErdosPrimeQ[p_Integer] := Module[{k}, |
ErdosPrimeQ[p_Integer] := Module[{k}, |
||
If[PrimeQ[p], |
If[PrimeQ[p], |
||
Line 796: | Line 796: | ||
Length[sel] |
Length[sel] |
||
sel = Select[Range[999999], ErdosPrimeQ]; |
sel = Select[Range[999999], ErdosPrimeQ]; |
||
{Length[sel], Last[sel]}</ |
{Length[sel], Last[sel]}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{2, 101, 211, 367, 409, 419, 461, 557, 673, 709, 769, 937, 967, 1009, 1201, 1259, 1709, 1831, 1889, 2141, 2221, 2309, 2351, 2411, 2437} |
<pre>{2, 101, 211, 367, 409, 419, 461, 557, 673, 709, 769, 937, 967, 1009, 1201, 1259, 1709, 1831, 1889, 2141, 2221, 2309, 2351, 2411, 2437} |
||
Line 803: | Line 803: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import math, sets, strutils, sugar |
||
const N = 1_000_000 |
const N = 1_000_000 |
||
Line 854: | Line 854: | ||
erdös7875 = p |
erdös7875 = p |
||
break |
break |
||
echo "\nThe 7875th Erdös prime is $#.".format(erdös7875)</ |
echo "\nThe 7875th Erdös prime is $#.".format(erdös7875)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 866: | Line 866: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 886: | Line 886: | ||
say 'Erdős primes < ' . (my $max = 2500) . ':'; |
say 'Erdős primes < ' . (my $max = 2500) . ':'; |
||
say join ' ', before { $_ > 2500 } @Erdős; |
say join ' ', before { $_ > 2500 } @Erdős; |
||
say "\nErdős prime #" . @Erdős . ' is ' . $Erdős[-1];</ |
say "\nErdős prime #" . @Erdős . ' is ' . $Erdős[-1];</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Erdős primes < 2500: |
<pre>Erdős primes < 2500: |
||
Line 894: | Line 894: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span> |
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">facts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">facts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span> |
||
Line 914: | Line 914: | ||
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> |
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The %,d%s Erdos prime is %,d (%s)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">),</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[$],</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The %,d%s Erdos prime is %,d (%s)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">),</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[$],</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 925: | Line 925: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers; |
||
my @factorial = 1, |[\*] 1..*; |
my @factorial = 1, |[\*] 1..*; |
||
Line 932: | Line 932: | ||
put 'Erdős primes < 2500:'; |
put 'Erdős primes < 2500:'; |
||
put @Erdős[^(@Erdős.first: * > 2500, :k)]»., |
put @Erdős[^(@Erdős.first: * > 2500, :k)]»., |
||
put "\nThe 7,875th Erdős prime is: " ~ @Erdős[7874].,</ |
put "\nThe 7,875th Erdős prime is: " ~ @Erdős[7874].,</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Erdős primes < 2500: |
<pre>Erdős primes < 2500: |
||
Line 940: | Line 940: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX program counts/displays the number of Erdos primes under a specified number N. */ |
||
parse arg n cols . /*get optional number of primes to find*/ |
parse arg n cols . /*get optional number of primes to find*/ |
||
if n=='' | n=="," then n= 2500 /*Not specified? Then assume default.*/ |
if n=='' | n=="," then n= 2500 /*Not specified? Then assume default.*/ |
||
Line 990: | Line 990: | ||
end /*k*/ /* [↑] only divide up to √ J */ |
end /*k*/ /* [↑] only divide up to √ J */ |
||
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/ |
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/ |
||
end /*j*/; return</ |
end /*j*/; return</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,011: | Line 1,011: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">// [dependencies] |
||
// primal = "0.3" |
// primal = "0.3" |
||
Line 1,052: | Line 1,052: | ||
println!("\nThe 7875th Erd\u{151}s prime is {}.", p); |
println!("\nThe 7875th Erd\u{151}s prime is {}.", p); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,065: | Line 1,065: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">func is_erdos_prime(p) { |
||
return true if p==2 |
return true if p==2 |
||
Line 1,081: | Line 1,081: | ||
say ("Erdős primes <= 2500: ", 1..2500 -> grep(is_erdos_prime)) |
say ("Erdős primes <= 2500: ", 1..2500 -> grep(is_erdos_prime)) |
||
say ("The 7875th Erdős prime is: ", is_erdos_prime.nth(7875))</ |
say ("The 7875th Erdős prime is: ", is_erdos_prime.nth(7875))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,091: | Line 1,091: | ||
Can't manage the stretch goal because integers are limited to signed 16 bit. |
Can't manage the stretch goal because integers are limited to signed 16 bit. |
||
< |
<syntaxhighlight lang="tinybasic"> LET P = 1 |
||
10 IF P > 2 THEN LET P = P + 2 |
10 IF P > 2 THEN LET P = P + 2 |
||
IF P < 3 THEN LET P = P + 1 |
IF P < 3 THEN LET P = P + 1 |
||
Line 1,128: | Line 1,128: | ||
IF A=K THEN RETURN |
IF A=K THEN RETURN |
||
LET A = A + 1 |
LET A = A + 1 |
||
GOTO 2010</ |
GOTO 2010</syntaxhighlight> |
||
{{out}}<pre>1 2 |
{{out}}<pre>1 2 |
||
2 101 |
2 101 |
||
Line 1,157: | Line 1,157: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<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,183: | Line 1,183: | ||
for (chunk in Lst.chunks(erdosLower, 10)) Fmt.print("$6d", chunk) |
for (chunk in Lst.chunks(erdosLower, 10)) Fmt.print("$6d", chunk) |
||
var show = 7875 |
var show = 7875 |
||
Fmt.print("\nThe $,r Erdős prime is $,d.", show, erdos[show-1])</ |
Fmt.print("\nThe $,r Erdős prime is $,d.", show, erdos[show-1])</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,196: | Line 1,196: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is prime |
||
int N, I; |
int N, I; |
||
[if N <= 2 then return N = 2; |
[if N <= 2 then return N = 2; |
||
Line 1,236: | Line 1,236: | ||
Text(0, "The "); IntOut(0, Cnt); |
Text(0, "The "); IntOut(0, Cnt); |
||
Text(0, "th Erdos prime is indeed "); IntOut(0, SN); CrLf(0); |
Text(0, "th Erdos prime is indeed "); IntOut(0, SN); CrLf(0); |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |