Attractive numbers: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
(Using Sieve of Eratosthenes module) |
||
Line 173: | Line 173: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
{{libheader|Action! Sieve of Eratosthenes}} |
|||
⚫ | |||
<lang Action!>INCLUDE "H6:SIEVE.ACT" |
|||
⚫ | |||
⚫ | |||
PROC Sieve() |
|||
BYTE i,j |
|||
FOR i=0 TO MAX |
|||
DO |
|||
primes(i)=1 |
|||
OD |
|||
primes(0)=0 primes(1)=0 |
|||
i=2 |
|||
WHILE i<=MAX |
|||
DO |
|||
IF primes(i)=1 THEN |
|||
FOR j=2*i TO MAX STEP i |
|||
DO |
|||
primes(j)=0 |
|||
OD |
|||
FI |
|||
i==+1 |
|||
OD |
|||
RETURN |
|||
⚫ | |||
BYTE count,f |
BYTE count,f |
||
Line 230: | Line 208: | ||
PROC Main() |
PROC Main() |
||
⚫ | |||
⚫ | |||
BYTE i |
BYTE i |
||
Put(125) PutE() ;clear the screen |
|||
Sieve() |
Sieve(primes,MAX+1) |
||
PrintF("Attractive numbers in range 1..%B:%E",MAX) |
PrintF("Attractive numbers in range 1..%B:%E",MAX) |
||
FOR i=1 TO MAX |
FOR i=1 TO MAX |
||
DO |
DO |
||
IF IsAttractive(i) THEN |
IF IsAttractive(i,primes) THEN |
||
PrintF("%B ",i) |
PrintF("%B ",i) |
||
FI |
FI |