Prime words: Difference between revisions

→‎{{header|Raku}}: specify base, specify version
(→‎{{header|Raku}}: DRY, more concise)
(→‎{{header|Raku}}: specify base, specify version)
Line 260:
 
say "\nNumber of words whose ordinal sum is prime: ",
@words.grep({ .comb».ord.sum.is-prime }).&{display +$_, .head(20)};
 
say "\n\nIterpreting the words as if they were base 36 numbers:";
 
say "\nNumber of words that are prime in base 36: ",
@words.grep({ !.contains(/\W/) && :36($_).is-prime }).&{display +$_, .head(20)};
 
say "\nNumber of words whose base 36 digital sum is prime: ",
@words.grep({ !.contains(/\W/) && .comb».parse-base(36).sum.is-prime }).&{display +$_, .head(20)};
 
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 26: ",
@words.hyper.grep({ !.contains(/<-alpha>/) && all(.comb».&from-base(26)).is-prime }).&{display +$_, $_, ''};
 
say "\nNumber of words that are prime using a custom base 26: ",
@words.grep({ !.contains(/<-alpha>/) && .&from-base(26).is-prime }).&{display +$_, .head(20)};
 
say "\nNumber of words whose digital sum is prime using a custom base 26: ",
@words.grep({ !.contains(/<-alpha>/) && .comb».&from-base(26).sum.is-prime }).&{display +$_, .head(20)};</lang>
{{out}}
<pre>Number of words whose ords are all prime: 36;
10,327

edits