Prime words: Difference between revisions

Content added Content deleted
(Added header)
(Added solution for Action!)
Line 23: Line 23:


<br><br>
<br><br>
=={{header|Action!}}==
In the following solution the input file is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used.
{{libheader|Action! Sieve of Eratosthenes}}
<lang Action!>INCLUDE "H6:SIEVE.ACT"

BYTE FUNC IsPrimeWord(CHAR ARRAY word BYTE ARRAY primes)
BYTE i,c

FOR i=1 TO word(0)
DO
c=word(i)
IF primes(c)=0 THEN
RETURN (0)
FI
OD
RETURN (1)

PROC FindPrimeWords(CHAR ARRAY fname BYTE ARRAY primes)
CHAR ARRAY line(256)
CHAR ARRAY tmp(256)
BYTE pos,dev=[1]

pos=2
Close(dev)
Open(dev,fname,4)
WHILE Eof(dev)=0
DO
InputSD(dev,line)
IF IsPrimeWord(line,primes) THEN
IF pos+line(0)>=39 THEN
PutE() pos=2
FI
Print(line) Put(32)
pos==+line(0)+1
FI
OD
Close(dev)
RETURN

PROC Main()
DEFINE MAX="128"
BYTE ARRAY primes(MAX+1)
CHAR ARRAY fname="H6:UNIXDICT.TXT"

Put(125) PutE() ;clear the screen
Sieve(primes,MAX+1)
FindPrimeWords(fname,primes)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Prime_words.png Screenshot from Atari 8-bit computer]
<pre>
a aaa age agee ak am ama e egg eke em emma g ga gag gage gam game gamma ge gee gem gemma gm k keg m ma mae magma make mamma me meek meg q
</pre>

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Does not distinguish between letters and non-letter ASCII codes (as with the REXX sample).
Does not distinguish between letters and non-letter ASCII codes (as with the REXX sample).