Prime words: Difference between revisions

Added Uiua solution
No edit summary
(Added Uiua solution)
 
(4 intermediate revisions by 3 users not shown)
Line 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}}==
Line 857 ⟶ 950:
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}}==
Line 1,573 ⟶ 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>
 
Line 1,578 ⟶ 1,708:
{{libheader|Wren-math}}
{{libheader|Wren-iterate}}
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./math" for Int
import "./iterate" for Stepped
 
// cache prime characters with codepoints between 33 and 255 say
69

edits