Home primes: Difference between revisions

1,627 bytes added ,  2 years ago
Add Factor
(→‎{{header|Raku}}: Doh. Fix stupid fencepost error)
(Add Factor)
Line 40:
;* [[oeis:A037274|OEIS:A037274 - Home primes for n >= 2]]
;* [[oeis:A056938|OEIS:A056938 - Concatenation chain for HP49]]
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: formatting kernel make math math.parser math.primes
math.primes.factors math.ranges present prettyprint sequences
sequences.extras ;
 
: squish ( seq -- n ) [ present ] map-concat dec> ;
 
: next ( m -- n ) factors squish ; inline
 
: (chain) ( n -- ) [ dup prime? ] [ dup , next ] until , ;
 
: chain ( n -- seq ) [ (chain) ] { } make ;
 
: chain. ( n -- )
chain [ last ] [ ] bi unclip "HP%2d = " printf
[ 1 + "HP%d(%d) = " printf ] each-index . ;
 
2 20 [a,b] [ chain. ] each</lang>
{{out}}
<pre>
HP 2 = 2
HP 3 = 3
HP 4 = HP22(1) = HP211(2) = 211
HP 5 = 5
HP 6 = HP23(1) = 23
HP 7 = 7
HP 8 = HP222(1) = HP2337(2) = HP31941(3) = HP33371313(4) = HP311123771(5) = HP7149317941(6) = HP22931219729(7) = HP112084656339(8) = HP3347911118189(9) = HP11613496501723(10) = HP97130517917327(11) = HP531832651281459(12) = HP3331113965338635107(13) = 3331113965338635107
HP 9 = HP33(1) = HP311(2) = 311
HP10 = HP25(1) = HP55(2) = HP511(3) = HP773(4) = 773
HP11 = 11
HP12 = HP223(1) = 223
HP13 = 13
HP14 = HP27(1) = HP333(2) = HP3337(3) = HP4771(4) = HP13367(5) = 13367
HP15 = HP35(1) = HP57(2) = HP319(3) = HP1129(4) = 1129
HP16 = HP2222(1) = HP211101(2) = HP3116397(3) = HP31636373(4) = 31636373
HP17 = 17
HP18 = HP233(1) = 233
HP19 = 19
HP20 = HP225(1) = HP3355(2) = HP51161(3) = HP114651(4) = HP3312739(5) = HP17194867(6) = HP194122073(7) = HP709273797(8) = HP39713717791(9) = HP113610337981(10) = HP733914786213(11) = HP3333723311815403(12) = HP131723655857429041(13) = HP772688237874641409(14) = HP3318308475676071413(15) = 3318308475676071413
</pre>
 
=={{header|Raku}}==
1,808

edits