Strange numbers: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: make generic) |
Catskill549 (talk | contribs) |
||
Line 286: | Line 286: | ||
425 427 429 461 463 464 468 469 470 472 |
425 427 429 461 463 464 468 469 470 472 |
||
474 475 479 492 494 496 497</pre> |
474 475 479 492 494 496 497</pre> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f STRANGE_NUMBERS.AWK |
|||
BEGIN { |
|||
start = 100 |
|||
stop = 500 |
|||
for (i=start; i<=stop; i++) { |
|||
flag = 1 |
|||
for (j=1; j<length(i); j++) { |
|||
if (!(is_prime(abs(substr(i,j,1)-substr(i,j+1,1))))) { |
|||
flag = 0 |
|||
break |
|||
} |
|||
} |
|||
if (flag == 1) { |
|||
printf("%d%1s",i,++count%10?"":"\n") |
|||
} |
|||
} |
|||
printf("\nStrange numbers %d-%d: %d\n",start,stop,count) |
|||
exit(0) |
|||
} |
|||
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) |
|||
} |
|||
function abs(x) { if (x >= 0) { return x } else { return -x } } |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
130 131 135 136 138 141 142 146 147 149 |
|||
161 163 164 168 169 181 183 185 186 202 |
|||
203 205 207 241 242 246 247 249 250 252 |
|||
253 257 258 270 272 274 275 279 292 294 |
|||
296 297 302 303 305 307 313 314 316 318 |
|||
350 352 353 357 358 361 363 364 368 369 |
|||
381 383 385 386 413 414 416 418 420 424 |
|||
425 427 429 461 463 464 468 469 470 472 |
|||
474 475 479 492 494 496 497 |
|||
Strange numbers 100-500: 87 |
|||
</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |