Primes whose first and last number is 3: Difference between revisions
Content added Content deleted
(Add Factor) |
|||
Line 79: | Line 79: | ||
3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 3643 3673 |
3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 3643 3673 |
||
3733 3793 3803 3823 3833 3853 3863 3923 3943 |
3733 3793 3803 3823 3833 3853 3863 3923 3943 |
||
</pre> |
|||
=={{header|Factor}}== |
|||
{{works with|Factor|0.99 2021-06-02}} |
|||
<lang factor>USING: formatting grouping io kernel lists lists.lazy math |
|||
math.functions math.primes sequences ; |
|||
: under ( list n -- list' ) '[ _ < ] lwhile ; |
|||
: (surrounded) ( n -- list ) |
|||
[ 1list 1 lfrom ] keep dup dup |
|||
'[ 10^ _ * _ + [ [ 10 + ] lfrom-by ] keep dup _ / + 10 - under ] |
|||
lmap-lazy lconcat lappend-lazy ; |
|||
: surrounded ( n upto -- list ) |
|||
[ (surrounded) ] [ under ] bi* [ prime? ] lfilter ; |
|||
: surrounded. ( n -- ) |
|||
dup "Primes under 10,000 beginning and ending with %d:\n" printf |
|||
10,000 surrounded list>array 10 group |
|||
[ [ "%6d" printf ] each nl ] each nl ; |
|||
{ 1 3 5 7 9 } [ surrounded. ] each |
|||
3 1,000,000 surrounded llength |
|||
"Found %d primes beginning and ending with 3 under 1,000,000.\n" printf</lang> |
|||
{{out}} |
|||
<pre> |
|||
Primes under 10,000 beginning and ending with 1: |
|||
11 101 131 151 181 191 1021 1031 1051 1061 |
|||
1091 1151 1171 1181 1201 1231 1291 1301 1321 1361 |
|||
1381 1451 1471 1481 1511 1531 1571 1601 1621 1721 |
|||
1741 1801 1811 1831 1861 1871 1901 1931 1951 |
|||
Primes under 10,000 beginning and ending with 3: |
|||
3 313 353 373 383 3023 3083 3163 3203 3253 |
|||
3313 3323 3343 3373 3413 3433 3463 3533 3583 3593 |
|||
3613 3623 3643 3673 3733 3793 3803 3823 3833 3853 |
|||
3863 3923 3943 |
|||
Primes under 10,000 beginning and ending with 5: |
|||
5 |
|||
Primes under 10,000 beginning and ending with 7: |
|||
7 727 757 787 797 7027 7057 7127 7177 7187 |
|||
7207 7237 7247 7297 7307 7417 7457 7477 7487 7507 |
|||
7517 7537 7547 7577 7607 7687 7717 7727 7757 7817 |
|||
7867 7877 7907 7927 7937 |
|||
Primes under 10,000 beginning and ending with 9: |
|||
919 929 9029 9049 9059 9109 9199 9209 9239 9319 |
|||
9349 9419 9439 9479 9539 9619 9629 9649 9679 9689 |
|||
9719 9739 9749 9769 9829 9839 9859 9929 9949 |
|||
Found 2251 primes beginning and ending with 3 under 1,000,000. |
|||
</pre> |
</pre> |
||