Numbers whose binary and ternary digit sums are prime: Difference between revisions

Content added Content deleted
(Add FOCAL)
(Added Perl)
Line 341: Line 341:
199
199
</pre>
</pre>

=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;
use feature 'say';
use List::Util 'sum';
use ntheory <is_prime todigitstring>;

sub test_digits { 0 != is_prime sum split '', todigitstring(shift, shift) }

my @p;
test_digits($_,2) and test_digits($_,3) and push @p, $_ for 1..199;
say my $result = @p . " matching numbers:\n" . (sprintf "@{['%4d' x @p]}", @p) =~ s/(.{40})/$1\n/gr;</lang>
{{out}}
<pre>61 matching numbers:
5 6 7 10 11 12 13 17 18 19
21 25 28 31 33 35 36 37 41 47
49 55 59 61 65 67 69 73 79 82
84 87 91 93 97 103 107 109 115 117
121 127 129 131 133 137 143 145 151 155
157 162 167 171 173 179 181 185 191 193
199</pre>


=={{header|Phix}}==
=={{header|Phix}}==