DµœcL’$Ḍµ€FÆPÐf
×⁵WÇÐĿFṪ<8
接受和返回整数的单子链接(1
0
否则为龟)。
在线尝试!
怎么样?
DµœcL’$Ḍµ€FÆPÐf Link 1: primes by digit removal: list of numbers e.g. [19790]
D cast to decimal list (vectorises) [[1,9,7,9,0]]
µ µ€ monadic chain for €ach:
$ last two links as a monad:
L length 5
’ decrement 4
œc combinations without replacement [[1,9,7,9],[1,9,7,0],[1,9,9,0],[1,7,9,0],[9,7,9,0]]
Ḍ cast from decimal list (vectorises) [1979,1970,1990,1790,9790]
F flatten (from a list of lists form the for €ach to a single list)
Ðf filter keep if:
ÆP is prime?
×⁵WÇÐĿFṪ<8 Main Link: number, n e.g. 1979
⁵ literal 10
× multiply 19790
(this is so the first number is tested as prime too)
W wrap in a list [19790]
ÐĿ loop, collecting results (including the input×10) while change still occurs:
Ç call the last (1) link as a monad [[19790],[1979],[197,199,179],[19,17,97,19,19,17,19,79],[7,7,7,7],[]]
F flatten [19790,1979,197,199,179,19,17,97,19,19,17,19,79,7,7,7,7]
Ṫ tail 7
<8 less than 8? 1
(if a single digit prime was reached this will be 1
otherwise it will be 0
e.g. an input of 4 yields 40 at the end which is not <8)