challenge - prime numbers where sum of squared digits of prime number is also prime
|
01-08-2018, 01:58 AM
Post: #14
|
|||
|
|||
challenge - prime numbers where sum of squared digits of prime number is also prime
This program takes an integer from level 1: in the stack and returns the prime that satisfies the condition of the challenge in level 2: and the value of the sum of the digits of the prime squared in level 1:, if flag 1 is set, the prime will be the previous prime or else the next prime. The program is stored in a variable called SDIP.
« WHILE 1 FS? { PREVPRIME } { NEXTPRIME } IFTE {0} OVER →STR WHILE DUP UNROT HEAD OBJ→ + SWAP TAIL DUP SIZE REPEAT END DROP SQ ΣLIST DUP ISPRIME? NOT REPEAT DROP END » SDIP [STO] running the program with flag 1 cleared and 2 on level 1: we have: 2: 11 1: 2 deleting 2 from level 1: and running the program again we have: 2: 23 1: 13 To see how many of such primes are that are less than 1000, we create a little program « 0 1000 1 SF @ SDIP will look for the previous prime WHILE DUP 11 > REPEAT SDIP DROP SWAP 1 + SWAP END DROP » running this program we have: 1: 53 To find the largest of such primes less than 100,000 we set flag 1 and run the program with 100000 in level 1:, we have: 2: 99971 1: 293 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)