Prime words: Difference between revisions

→‎{{header|Raku}}: Add a Raku solution
(add freebasic)
(→‎{{header|Raku}}: Add a Raku solution)
Line 138:
meg
q</pre>
 
=={{header|Raku}}==
Another in a continuing series of tasks that are a minimal variation of previous ones. This is essentially [[Smarandache prime-digital sequence]] using ords instead of numerical digits.
Sigh.
 
In an effort to anticipate / head-off a rash of tiny variant tasks, a series of one-liners:
 
<lang perl6>my @words = 'unixdict.txt'.IO.words».fc;
 
say 'Number of words whose ords are all prime: ',
@words.map({ next unless all(.comb.».ord).is-prime; $_ }).&{"{+$_};\n{.join: ', '}"};
 
say "\nNumber of words whose ordinal sum is prime: ",
@words.map({ $_ if .comb».ord.sum.is-prime }).&{"{+$_};\nFirst 20: {.head(20).join: ', '} ..."};
 
say "\n\nIterpreting the words as if they were base 36 numbers:";
 
say "\nNumber of words that are prime in base 36: ",
@words.map({ next if .contains(/\W/); $_ if :36($_).is-prime }).&{"{+$_};\nFirst 20: {.head(20).join: ', '} ..."};
 
say "\nNumber of words whose base 36 digital sum is prime: ",
@words.map({ next if .contains(/\W/); $_ if .comb».parse-base(36).sum.is-prime }).&{"{+$_};\nFirst 20: {.head(20).join: ', '} ..."};
 
use Base::Any:ver<0.1.2>;
set-digits('a'..'z');
 
say "\n\nTests using a custom base 26 where 'a' through 'z' is 0 through 25 and words are case folded:";
 
say "\nNumber of words whose 'digits' are all prime using a custom base: ",
@words.map({ next if .contains(/<-alpha>/); $_ if all(.comb».&from-base(26)).is-prime }).&{"{+$_};\n{.join: ', '}"};
 
say "\nNumber of words that are prime using a custom base: ",
@words.map({ next if .contains(/<-alpha>/); $_ if .&from-base(26).is-prime }).&{"{+$_};\nFirst 20: {.head(20).join: ', '} ..."};
 
say "\nNumber of words whose digital sum is prime using a custom base: ",
@words.map({ next if .contains(/<-alpha>/); $_ if .comb».&from-base(26).sum.is-prime }).&{"{+$_};\nFirst 20: {.head(20).join: ', '} ..."};</lang>
{{out}}
<pre>Number of words whose ords are all prime: 36;
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
 
Number of words whose ordinal sum is prime: 3778;
First 20: 10th, 9th, a, a's, aau, ababa, abate, abhorred, abject, ablate, aboard, abrade, abroad, absentee, absentia, absolute, absorptive, absurd, abusive, accelerate ...
 
 
Iterpreting the words as if they were base 36 numbers:
 
Number of words that are prime in base 36: 1106;
First 20: 10th, 1st, 2nd, 5th, 6th, 7th, abandon, abbott, abdomen, ablution, abolish, abort, abrupt, absorb, abstention, abstract, abutted, accept, accident, acid ...
 
Number of words whose base 36 digital sum is prime: 4740;
First 20: 10th, 3rd, 7th, aba, abacus, abalone, abase, abater, abelian, abelson, aberrant, abeyant, ablaze, abort, aboveground, abraham, abrasion, abrasive, abreact, abridge ...
 
 
Tests using a custom base 26 where 'a' through 'z' is 0 through 25 and words are case folded:
 
Number of words whose 'digits' are all prime using a custom base: 30;
c, cdc, cf, crt, ct, d, dc, dr, f, fcc, fl, ft, ftc, h, l, ltd, n, nc, ncr, nd, nh, nrc, r, rd, t, tn, tnt, ttl, tx, x
 
Number of words that are prime using a custom base: 987;
First 20: abhorrent, abolish, abreact, absurd, ac, act, actual, actuarial, ad, adjutant, adult, advisor, aerosol, aft, agent, agricultural, ah, aid, ajar, al ...
 
Number of words whose digital sum is prime using a custom base: 5473;
First 20: ababa, aback, abacus, abalone, abase, abater, abc, abdicate, abdomen, abe, abelian, abelson, aberrant, abeyant, ablaze, abolish, abominate, aborigine, aboveground, abraham ...</pre>
 
=={{header|REXX}}==
10,339

edits