Ludic numbers: Difference between revisions

Added solution for Action!
No edit summary
(Added solution for Action!)
Line 368:
221 223 227
233 235 239
</pre>
 
=={{header|Action!}}==
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU.
<lang Action!>DEFINE NOTLUDIC="0"
DEFINE LUDIC="1"
DEFINE UNKNOWN="2"
 
PROC LudicSieve(BYTE ARRAY a INT count)
INT i,j,k
 
SetBlock(a,count,UNKNOWN)
a(0)=NOTLUDIC
a(1)=LUDIC
 
i=2
WHILE i<count
DO
IF a(i)=UNKNOWN THEN
a(i)=LUDIC
j=i k=0
WHILE j<count
DO
IF a(j)=UNKNOWN THEN
k==+1
IF k=i THEN
a(j)=NOTLUDIC
k=0
FI
FI
j==+1
OD
FI
i==+1
Poke(77,0) ;turn off the attract mode
OD
RETURN
 
PROC PrintLudicNumbers(BYTE ARRAY a INT count,first,last)
INT i,j
 
i=1 j=0
WHILE i<count AND j<=last
DO
IF a(i)=LUDIC THEN
IF j>=first THEN
PrintI(i) Put(32)
FI
j==+1
FI
i==+1
OD
PutE() PutE()
RETURN
 
INT FUNC CountLudicNumbers(BYTE ARRAY a INT max)
INT i,res
 
res=0
FOR i=1 TO max
DO
IF a(i)=LUDIC THEN
res==+1
FI
OD
RETURN (res)
 
PROC Main()
DEFINE COUNT="22000"
BYTE ARRAY lud(COUNT+1)
INT i,n
 
PrintE("Please wait...")
LudicSieve(lud,COUNT+1)
Put(125) PutE() ;clear the screen
 
PrintE("First 25 ludic numbers:")
PrintLudicNumbers(lud,COUNT+1,0,24)
 
n=CountLudicNumbers(lud,1000)
PrintF("There are %I ludic numbers <= 1000%E%E",n)
 
PrintE("2000'th..2005'th ludic numbers:")
PrintLudicNumbers(lud,COUNT+1,1999,2004)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Ludic_numbers.png Screenshot from Atari 8-bit computer]
<pre>
First 25 ludic numbers:
1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107
 
There are 142 ludic numbers <= 1000
 
2000'th..2005'th ludic numbers:
21475 21481 21487 21493 21503 21511
</pre>
 
Anonymous user