Numbers whose binary and ternary digit sums are prime: Difference between revisions
Content added Content deleted
(Add Plain English) |
Catskill549 (talk | contribs) (added AWK) |
||
Line 181: | Line 181: | ||
157 162 167 171 173 179 181 185 191 193 |
157 162 167 171 173 179 181 185 191 193 |
||
199</pre> |
199</pre> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f NUMBERS_WHICH_BINARY_AND_TERNARY_DIGIT_SUM_ARE_PRIME.AWK |
|||
# converted from C |
|||
BEGIN { |
|||
start = 0 |
|||
stop = 199 |
|||
for (i=start; i<=stop; i++) { |
|||
if (is_prime(sum_digits(i,2)) && is_prime(sum_digits(i,3))) { |
|||
printf("%4d%1s",i,++count%10?"":"\n") |
|||
} |
|||
} |
|||
printf("\nBinary and ternary digit sums are both prime %d-%d: %d\n",start,stop,count) |
|||
exit(0) |
|||
} |
|||
function sum_digits(n,base, sum) { |
|||
do { |
|||
sum += n % base |
|||
} while (n = int(n/base)) |
|||
return(sum) |
|||
} |
|||
function is_prime(x, i) { |
|||
if (x <= 1) { |
|||
return(0) |
|||
} |
|||
for (i=2; i<=int(sqrt(x)); i++) { |
|||
if (x % i == 0) { |
|||
return(0) |
|||
} |
|||
} |
|||
return(1) |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
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 |
|||
Binary and ternary digit sums are both prime 0-199: 61 |
|||
</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |