Prime words: Difference between revisions

Added XPL0 example.
(Added 11l)
(Added XPL0 example.)
Line 1,417:
<pre>
Prime words in unixdict.txt are:
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|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
 
string 0; \use zero-terminated strings
int I, Ch;
char Word(25);
def LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I);
OpenI(3);
repeat I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch = EOF then quit;
if Ch = LF then
[Word(I):= 0; Text(0, Word); CrLf(0);
quit;
];
if not IsPrime(Ch) then
[repeat Ch:= ChIn(3) until Ch=LF or Ch=EOF;
quit;
];
Word(I):= Ch;
I:= I+1;
];
until Ch = EOF;
]</lang>
 
{{out}}
<pre>
a
aaa
772

edits