Special neighbor primes: Difference between revisions
Content added Content deleted
m (oops) |
(Added solution for Action!) |
||
Line 6: | Line 6: | ||
Find and show here in base ten if '''p<sub>1</sub>+ p<sub>2</sub> -1''' is prime, where '''p<sub>1</sub>, p<sub>2</sub> < 100'''. |
Find and show here in base ten if '''p<sub>1</sub>+ p<sub>2</sub> -1''' is prime, where '''p<sub>1</sub>, p<sub>2</sub> < 100'''. |
||
<br><br> |
<br><br> |
||
=={{header|Action!}}== |
|||
{{libheader|Action! Sieve of Eratosthenes}} |
|||
<lang Action!>INCLUDE "H6:SIEVE.ACT" |
|||
INT FUNC GetNextPrime(INT i BYTE ARRAY primes) |
|||
DO |
|||
i==+1 |
|||
UNTIL primes(i) |
|||
OD |
|||
RETURN (i) |
|||
PROC Main() |
|||
DEFINE MAXPRIME="99" |
|||
DEFINE MAX="200" |
|||
BYTE ARRAY primes(MAX+1) |
|||
INT i,p |
|||
Put(125) PutE() ;clear the screen |
|||
Sieve(primes,MAX+1) |
|||
FOR i=2 TO MAXPRIME |
|||
DO |
|||
IF primes(i) THEN |
|||
p=GetNextPrime(i,primes) |
|||
IF p<=MAXPRIME AND primes(i+p-1)=1 THEN |
|||
PrintF("%I+%I-1=%I%E",i,p,i+p-1) |
|||
FI |
|||
FI |
|||
OD |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Special_neighbor_primes.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
3+5-1=7 |
|||
5+7-1=11 |
|||
7+11-1=17 |
|||
11+13-1=23 |
|||
13+17-1=29 |
|||
19+23-1=41 |
|||
29+31-1=59 |
|||
31+37-1=67 |
|||
41+43-1=83 |
|||
43+47-1=89 |
|||
61+67-1=127 |
|||
67+71-1=137 |
|||
73+79-1=151 |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |