Prime words: Difference between revisions

Added Uiua solution
(→‎{{header|Ruby}}: Added Ruby)
(Added Uiua solution)
 
(25 intermediate revisions by 19 users not shown)
Line 1:
{{draft task|Prime numbersNumbers}}
A word is a   ''prime word''   if all its individual letters   (expressed as an ASCII decimal code)   are primes.
 
Line 23:
 
<br><br>
=={{header|11l}}==
<syntaxhighlight lang="11l">F is_prime(Int a)
I a == 2
R 1B
I a < 2 | a % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(a))).step(2)
I a % i == 0
R 0B
R 1B
 
Set[Int] prime_chars
L(c) ‘a’.code .. ‘z’.code
I is_prime(c)
prime_chars.add(c)
L(c) ‘A’.code .. ‘Z’.code
I is_prime(c)
prime_chars.add(c)
 
L(word) File(‘unixdict.txt’).read().split("\n")
L(c) word
I c.code !C prime_chars
L.break
L.was_no_break
print(word)</syntaxhighlight>
 
{{out}}
<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|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}}
<syntaxhighlight 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</syntaxhighlight>
{{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}}==
Does not distinguish between letters and non-letter ASCII codes (as with the REXX sample).
{{libheader|ALGOL 68-primes}}
<lang algol68># find words whose character codes are primes #
<syntaxhighlight lang="algol68"># find words whose character codes are primes #
IF FILE input file;
STRING file name = "unixdict.txt";
Line 45 ⟶ 166:
END
);
# construct a sieve of primes up to the maximum character #
PR read "primes.incl.a68" PR
[ 0 : max abs char ]BOOL s;
FOR i TO UPB[]BOOL s DO= s[PRIMESIEVE i ] :=max TRUEabs ODchar;
s[ 0 ] := s[ 1 ] := FALSE;
FOR i FROM 2 TO ENTIER sqrt( UPB s ) DO
IF s[ i ] THEN FOR p FROM i * i BY i TO UPB s DO s[ p ] := FALSE OD FI
OD;
# find the prime words #
INT prime count := 0;
Line 66 ⟶ 183:
OD;
close( input file )
FI</langsyntaxhighlight>
{{out}}
<pre>
Line 106 ⟶ 223:
36: q
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">words: read.lines relative "unixdict.txt"
 
loop words 'word [
if every? split word 'ch -> prime? to :integer to :char ch ->
print word
]</syntaxhighlight>
 
{{out}}
 
<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|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f PRIME_WORDS.AWK unixdict.txt
BEGIN {
Line 136 ⟶ 302:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 143 ⟶ 309:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <cstdlib>
#include <fstream>
Line 172 ⟶ 338:
}
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
Contents of prime_sieve.hpp:
<langsyntaxhighlight lang="cpp">#ifndef PRIME_SIEVE_HPP
#define PRIME_SIEVE_HPP
 
Line 226 ⟶ 392:
}
 
#endif</langsyntaxhighlight>
 
{{out}}
Line 240 ⟶ 406:
33: me 34: meek 35: meg 36: q
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
function IsPrime(N: int64): boolean;
{Fast, optimised prime test}
var I,Stop: int64;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N+0.0));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
 
procedure ShowPrimeWords(Memo: TMemo);
var I,N,Sum,Cnt: integer;
var NS,S: string;
 
function IsPrimeWord(S: string): boolean;
var I: integer;
begin
Result:=False;
for I:=1 to Length(S) do
if not IsPrime(byte(S[I])) then exit;
Result:=True;
end;
 
 
begin
Cnt:=0;
S:='';
{Iterate all entries in dictionary}
for I:=0 to UnixDict.Count-1 do
if IsPrimeWord(UnixDict[I]) then
begin
Inc(Cnt);
Memo.Lines.Add(UnixDict[I]);
end;
Memo.Lines.Add('Count = '+IntToStr(Cnt));
end;
 
</syntaxhighlight>
{{out}}
<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
Count = 36
Elapsed Time: 72.759 ms.
 
</pre>
 
 
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<langsyntaxhighlight lang="factor">USING: io.encodings.ascii io.files math.primes prettyprint sequences ;
 
"unixdict.txt" ascii file-lines [ [ prime? ] all? ] filter .</langsyntaxhighlight>
{{out}}
<pre style="height: 45ex">
Line 289 ⟶ 555:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
dim shared as boolean prime(0 to 29) =_
{false, true, false, true, true, false, false, true, false, true, false, false, true, false,_
Line 317 ⟶ 583:
close #1
end
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 356 ⟶ 622:
meg
q</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
mda(0) = {NO, YES, NO, YES, YES, NO, NO, YES, NO, YES, NO, NO, YES,¬
NO, NO, NO, YES, NO, YES, YES, NO, YES, YES, NO, YES, NO, NO, NO, NO}
 
local fn WordList as CFArrayRef
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = lcase(fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL ))
CFArrayRef wordArr = fn StringComponentsSeparatedByString( string, @"\n" )
CFMutableArrayRef mutArr = fn MutableArrayNew
CFStringRef tempStr
for tempStr in wordArr
CFRange range = fn StringRangeOfStringWithOptions( tempStr, @"^[a-z]+$", NSRegularExpressionSearch )
if range.location != NSNotFound then MutableArrayAddObject( mutArr, tempStr )
next
end fn = mutArr
 
local fn IsPrimeLetter( s as CFStringRef ) as BOOL
NSUInteger index = 0
BOOL result = NO
unichar n = fn StringCharacterAtIndex( s, index )
if n mod 2 == 0 then exit fn = NO
result = mda_integer( (n-65)/2 )
end fn = result
 
local fn IsPrimeWord( s as CFStringRef ) as BOOL
NSUInteger i, count = len(s)
for i = 0 to count -1
if fn IsPrimeLetter( mid( s, i, 1 ) ) = NO then exit fn = NO
next
end fn = YES
 
local fn FindPrimeWords
CFArrayRef wordArr = fn WordList
CFStringRef wordStr
for wordStr in wordArr
if wordStr = @"" then break
if fn IsPrimeWord( wordStr ) = YES then printf @"%@", wordStr
next
end fn
 
fn FindPrimeWords
 
HandleEvents
</syntaxhighlight>
{{output}}
<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|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 421 ⟶ 780:
}
}
}</langsyntaxhighlight>
 
{{out}}
<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|J}}==
<syntaxhighlight lang="j"> ($~ _2 */\ q:@#)(#~ (1 */@p: 3 u: ])@>) cutLF fread'unixdict.txt'
┌─────┬───┬─────┬────┬─────┬───┬────┬───┬────┐
│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 │
└─────┴───┴─────┴────┴─────┴───┴────┴───┴────┘</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
A suitable implementation of `is_prime` is given at
[[Erd%C5%91s-primes#jq]] and is therefore not repeated here.
 
The task description suggests that perhaps the appropriate
definition of `is_prime_word` should focus on the alphabetic characters,
perhaps along the lines of:
<syntaxhighlight lang="jq">def is_prime_word: all(gsub("[^A-Za-z]";"") | explode[]; is_prime);
</syntaxhighlight>
All such variations are as easy to accommodate as to envision, but for unixdict.txt the following suffices:
<syntaxhighlight lang="jq">def is_prime_word: all(explode[]; is_prime);</syntaxhighlight>
<syntaxhighlight lang="jq">
inputs | select(is_prime_word)</syntaxhighlight>
{{out}}
Invocation (example): jq -Rrn -f prime-words.jq unixdict.txt
<pre>
a
aaa
Line 466 ⟶ 894:
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<langsyntaxhighlight lang="julia">const primelettervalues = [67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113]
isprimeword(w, _) = all(c -> Int(c) in primelettervalues, collect(w)) ? w : ""
foreachword("unixdict.txt", isprimeword, colwidth=10, numcols=9)
</langsyntaxhighlight>{{out}}
<pre>
Word source: unixdict.txt
Line 478 ⟶ 906:
ma mae magma make mamma me meek meg q
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">dict=Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt","String"];
dict//=StringSplit[#,"\n"]&;
chars=CharacterRange["A","Z"]~Join~CharacterRange["a","z"];
chars//=Select[ToCharacterCode/*First/*PrimeQ];
Select[dict,StringMatchQ[Repeated[Alternatives@@chars]]]//Column</syntaxhighlight>
{{out}}
<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|MiniScript}}==
This implementation is for use with the [http://miniscript.org/MiniMicro Mini Micro] version of MiniScript. The command-line version does not include a HTTP library. Modify the declaration of wordList object to use the file class to read a local copy of the word list file.
<syntaxhighlight lang="miniscript">
isPrimeWord = function(word)
if word.len == 0 then return false
for ch in word.split("")
if "aegkmq".indexOf(ch) == null then return false
end for
return true
end function
 
wordList = http.get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").split(char(10))
primes = []
for word in wordList
if isPrimeWord(word) then primes.push(word)
end for
 
print primes.join(", ")
</syntaxhighlight>
{{out}}
<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|Nim}}==
<syntaxhighlight lang="nim">import strformat, strutils
 
func isPrime(n: Natural): bool =
if n < 2: return false
if n mod 2 == 0: return n == 2
if n mod 3 == 0: return n == 3
var d = 5
while d * d <= n:
if n mod d == 0: return false
inc d, 2
if n mod d == 0: return false
inc d, 4
result = true
 
# Build set of prime characters.
const PrimeChars = static:
var pchars: set[char]
for c in Letters:
if ord(c).isPrime: pchars.incl c
pchars
 
var count = 0
for word in "unixdict.txt".lines:
if word.allCharsInSet(PrimeChars):
inc count
echo &"{count:2}: {word}"</syntaxhighlight>
 
{{out}}
<pre> 1: a
2: aaa
3: age
4: agee
5: ak
6: am
7: ama
8: e
9: egg
10: eke
11: em
12: emma
13: g
14: ga
15: gag
16: gage
17: gam
18: game
19: gamma
20: ge
21: gee
22: gem
23: gemma
24: gm
25: k
26: keg
27: m
28: ma
29: mae
30: magma
31: make
32: mamma
33: me
34: meek
35: meg
36: q</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 487 ⟶ 1,049:
my $pat = join '', grep +(1 x ord) !~ /^(11+)\1+$/, 'a'..'z', 'A'..'Z';
@ARGV = 'unixdict.txt';
print join('', grep /^[$pat]+$/, <>) =~ tr/\n/ /r =~ s/.{1,71}\K /\n/gr;</langsyntaxhighlight>
{{out}}
<pre>
Line 495 ⟶ 1,057:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function sap(string word) return sum(apply(word,is_prime))==length(word) end function
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
sequence words = filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),sap)
<span style="color: #008080;">function</span> <span style="color: #000000;">sap</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">))==</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
printf(1,"%d prime words found: %s\n",{length(words),join(shorten(words,"",3),", ")})</lang>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">sap</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d prime words found: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 504 ⟶ 1,069:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Put "c:\unixdict.txt" into a path.
Line 529 ⟶ 1,094:
If the substring's first's target is not prime, say no.
Add 1 to the substring's first.
Repeat.</langsyntaxhighlight>
{{out}}
<pre style="height:18em">
Line 568 ⟶ 1,133:
meg
q
</pre>
 
=={{header|Python}}==
Given that the set is known and quite small, 52 in length, a bit of pre-processing to determine all prime positioned characters before hand will speed up the task significantly rather than determining it every time for every word in the list.
 
Here is the brute force pre-processor, again this can be done easily manually, but if you are feeling lazy, like me :)
<syntaxhighlight lang="python">
for i in range(65,123):
check = 1
for j in range(2,i):
if i%j == 0:
check = 0
if check==1:
print(chr(i),end='')
</syntaxhighlight>
 
This produces the following string :
 
<pre>
CGIOSYaegkmq
</pre>
 
It's possible to speed it up even more by dropping capitals since the file only contains lower case characters, but we will give that a pass.....
 
And here's the main program which hardcodes the output of the pre-processor above. As always :
 
Tested on Python 3+, the file download will work only if the link is still active. It is possible that you may be able to fetch the file in your browser but download via code may still fail. Check whether you are connected to a VPN, it works on open networks.
 
<syntaxhighlight lang="python">
#Aamrun, 6th November 2021
 
import urllib.request
from collections import Counter
urllib.request.urlretrieve("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt", "unixdict.txt")
dictionary = open("unixdict.txt","r")
wordList = dictionary.read().split('\n')
dictionary.close()
primeSet = set("CGIOSYaegkmq")
 
[print(word) for word in wordList if len(set(word).difference(primeSet))==0]
</syntaxhighlight>
 
And here's the final output :
{{Output}}
<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|Quackery}}==
 
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]].
 
<syntaxhighlight lang="Quackery"> 128 eratosthenes
 
[]
$ "rosetta/unixdict.txt" sharefile drop nest$
witheach
[ true over
witheach
[ isprime not if
[ not conclude ] ]
iff [ nested join ]
else drop ]
46 wrap$</syntaxhighlight>
 
{{out}}
 
<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>
 
Line 576 ⟶ 1,252:
In an effort to anticipate / head-off a rash of tiny variant tasks, a series of one-liners:
 
<syntaxhighlight lang="raku" perl6line>my @words = 'unixdict.txt'.IO.words».fc;
 
sub display ($n, @n, $s = "First 20: ") {"$n;\n{$s}{@n.join: ', '}"}
Line 626 ⟶ 1,302:
 
say "\nNumber of words that are prime in custom base 26, whose digits are all prime, and whose digital sum is prime: ",
@words.hyper.grep({ !.contains(/<-alpha>/) && all(.comb».&from-base(26)).is-prime && .&from-base(26).is-prime && .comb».&from-base(26).sum.is-prime }).&{display +$_, $_, ''};</langsyntaxhighlight>
{{out}}
<pre>Number of words whose ords are all prime: 36;
Line 675 ⟶ 1,351:
=={{header|REXX}}==
No attempt was made to exclude any "word" if it contained any non-letter (Latin alphabet) characters.
<langsyntaxhighlight lang="rexx">/*REXX program finds words whose ASCII code for its letters are prime (in a dictionary).*/
parse arg iFID . /*obtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID='unixdict.txt' /*Not specified? Then use the default.*/
Line 701 ⟶ 1,377:
67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 ,
157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251
@.= 0; do j=1 for words(p); _= word(p, j); @._= 1; end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 749 ⟶ 1,425:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 774 ⟶ 1,450:
see "Prime words are:" + nl
see Words
</syntaxhighlight>
</lang>
Output:
<pre>
Line 817 ⟶ 1,493:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'prime'
 
puts File.open("unixdict.txt").each.select{|line| line.chomp.chars.all?{|c| c.ord.prime?} }
</syntaxhighlight>
</lang>
{{out}}
<pre>a
Line 859 ⟶ 1,535:
q
</pre>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// [dependencies]
// primal = "0.3"
 
Line 888 ⟶ 1,565:
Err(error) => eprintln!("{}", error),
}
}</langsyntaxhighlight>
 
{{out}}
Line 904 ⟶ 1,581:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
class BitArray {
Line 973 ⟶ 1,650:
} catch {
print(error.localizedDescription)
}</langsyntaxhighlight>
 
{{out}}
Line 1,013 ⟶ 1,690:
meg
q
</pre>
 
=={{header|Uiua}}==
{{works with|Uiua|0.11.0-dev.1}}
<syntaxhighlight lang="Uiua">
⊜□ ≠@\n. &fras "unixdict.txt"
Ps ← ⇌◌⍢(▽≠0◿⊢..⟜(⊂⊢)|>0⧻.):[]+2⇡256 # Build primes
Pc ← ▽:⟜(∊-@\0)⊂¯.+@a⇡26Ps # Test A-Za-z for primal ASCII codes
▽:⟜(≡(/×◇∊)⊙¤):Pc
</syntaxhighlight>
{{out}}
<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|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-traititerate}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
import "./math" for Int
import "./traititerate" for Stepped
 
// cache prime characters with codepoints between 33 and 255 say
Line 1,032 ⟶ 1,722:
for (word in words) {
if (word.all { |c| primeChars.contains(c) }) System.print(word)
}</langsyntaxhighlight>
 
{{out}}
<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}}==
<syntaxhighlight 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;
]</syntaxhighlight>
 
{{out}}
<pre>
a
aaa
62

edits