Jump to content

Pernicious numbers: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 309:
<pre>3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886 </pre>
 
=={{header|AWK}}==
<lang AWK>
Line 413 ⟶ 414:
return 0;
}</lang>
{{out}}
<pre>
3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886
</pre>
 
=={{header|C++}}==
<lang cpp>
#include <iostream>
using namespace std;
 
int main() {
int cnt = 0, cnt2, cnt3, tmp, binary[8];
for (int i = 3; cnt < 25; i++) {
tmp = i;
cnt2 = 0;
cnt3 = 0;
for (int j = 7; j > 0; j--) {
binary[j] = tmp % 2;
tmp /= 2;
}
binary[0] = tmp;
for (int j = 0; j < 8; j++) {
if (binary[j] == 1) {
cnt2++;
}
}
for (int j = 2; j <= (cnt2 / 2); j++) {
if (cnt2 % j == 0) {
cnt3++;
break;
}
}
if (cnt3 == 0 && cnt2 != 1) {
cout << i << endl;
cnt++;
}
}
 
cout << endl;
int binary2[31];
 
for (int i = 888888877; i <= 888888888; i++) {
tmp = i;
cnt2 = 0;
cnt3 = 0;
for (int j = 30; j > 0; j--) {
binary2[j] = tmp % 2;
tmp /= 2;
}
binary2[0] = tmp;
for (int j = 0; j < 31; j++) {
if (binary2[j] == 1) {
cnt2++;
}
}
for (int j = 2; j <= (cnt2 / 2); j++) {
if (cnt2 % j == 0) {
cnt3++;
break;
}
}
if (cnt3 == 0 && cnt2 != 1) {
cout << i << endl;
}
}
}
</lang>
{{out}}
<pre>
Line 551 ⟶ 484:
}
}</lang>
{{out}}
<pre>
3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886
</pre>
 
=={{header|C++}}==
<lang cpp>
#include <iostream>
using namespace std;
 
int main() {
int cnt = 0, cnt2, cnt3, tmp, binary[8];
for (int i = 3; cnt < 25; i++) {
tmp = i;
cnt2 = 0;
cnt3 = 0;
for (int j = 7; j > 0; j--) {
binary[j] = tmp % 2;
tmp /= 2;
}
binary[0] = tmp;
for (int j = 0; j < 8; j++) {
if (binary[j] == 1) {
cnt2++;
}
}
for (int j = 2; j <= (cnt2 / 2); j++) {
if (cnt2 % j == 0) {
cnt3++;
break;
}
}
if (cnt3 == 0 && cnt2 != 1) {
cout << i << endl;
cnt++;
}
}
 
cout << endl;
int binary2[31];
 
for (int i = 888888877; i <= 888888888; i++) {
tmp = i;
cnt2 = 0;
cnt3 = 0;
for (int j = 30; j > 0; j--) {
binary2[j] = tmp % 2;
tmp /= 2;
}
binary2[0] = tmp;
for (int j = 0; j < 31; j++) {
if (binary2[j] == 1) {
cnt2++;
}
}
for (int j = 2; j <= (cnt2 / 2); j++) {
if (cnt2 % j == 0) {
cnt3++;
break;
}
}
if (cnt3 == 0 && cnt2 != 1) {
cout << i << endl;
}
}
}
</lang>
{{out}}
<pre>
Line 1,155 ⟶ 1,156:
<pre>3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886 </pre>
 
=={{header|jq}}==
{{works with|jq|1.4}}
Line 1,493 ⟶ 1,495:
<pre>@[3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 31, 33, 34, 35, 36]
@[888888877, 888888878, 888888880, 888888883, 888888885, 888888886]</pre>
 
=={{header|PARI/GP}}==
<lang parigp>pern(n)=isprime(hammingweight(n))
select(pern, [1..36])
select(pern,[888888877..888888888])</lang>
{{out}}
<pre>%1 = [3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 31, 33, 34, 35, 36]
%2 = [888888877, 888888878, 888888880, 888888883, 888888885, 888888886]</pre>
 
=={{header|Panda}}==
Line 1,514 ⟶ 1,508:
<pre>3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886</pre>
 
=={{header|PARI/GP}}==
<lang parigp>pern(n)=isprime(hammingweight(n))
select(pern, [1..36])
select(pern,[888888877..888888888])</lang>
{{out}}
<pre>%1 = [3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 31, 33, 34, 35, 36]
%2 = [888888877, 888888878, 888888880, 888888883, 888888885, 888888886]</pre>
 
=={{header|Pascal}}==
Line 1,651 ⟶ 1,653:
print "@pern\n";
print join(" ", grep { is_prime(hammingweight($_)) } 888888877 .. 888888888), "\n";</lang>
 
=={{header|Perl 6}}==
Straightforward implementation using Perl 6's ''is-prime'' built-in subroutine.
<lang perl6>sub is-pernicious(Int $n --> Bool) {
is-prime [+] $n.base(2).comb;
}
 
say (grep &is-pernicious, 0 .. *)[^25];
say grep &is-pernicious, 888_888_877 .. 888_888_888;</lang>
{{out}}
<pre>3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886</pre>
 
=={{header|Phix}}==
Line 2,127 ⟶ 2,117:
display all pernicious numbers between 888,888,877 and 888,888,888 (inclusive).
888888877, 888888878, 888888880, 888888883, 888888885, 888888886</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
Straightforward implementation using Perl 6's ''is-prime'' built-in subroutine.
<lang perl6>sub is-pernicious(Int $n --> Bool) {
is-prime [+] $n.base(2).comb;
}
 
say (grep &is-pernicious, 0 .. *)[^25];
say grep &is-pernicious, 888_888_877 .. 888_888_888;</lang>
{{out}}
<pre>3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886</pre>
 
=={{header|REXX}}==
Line 2,510 ⟶ 2,513:
888888877 888888878 888888880 888888883 888888885 888888886 888888889
</pre>
 
=={{header|Tcl}}==
Line 2,586 ⟶ 2,588:
<pre> 3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
888888877 888888878 888888880 888888883 888888885 888888886 </pre>
 
=={{header|VBScript}}==
<lang vb>'check if the number is pernicious
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.