How to resolve the algorithm Smarandache-Wellin primes step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Smarandache-Wellin primes step by step in the J programming language

Table of Contents

Problem Statement

A Smarandache-Wellin number (S-W number for short) is an integer that in a given base is the concatenation of the first n prime numbers written in that base. A base of 10 will be assumed for this task. A Derived S-W number (not an 'official' term) is an integer formed from a S-W number by working out the number of times each of the digits 0 to 9 occurs in that number, concatenating those frequencies in the same order (i.e. frequency of '0' first, frequency of '1' second etc) and removing any leading zeros. '23571113' is the sixth S-W number formed by concatenating the first 6 primes: 2, 3, 5, 7, 11 and 13. The corresponding Derived S-W number is '312010100' because '1' occurs 3 times, '3' occurs twice and '2', '5' and '7' all occur once. Find and show the index in the sequence (starting from 1), the total number of digits and the last prime used to form the fourth, fifth, sixth, seventh and (optionally) the eighth S-W numbers which are prime or probably prime with reasonable certainty. It is unknown whether there are any more but, if you fancy searching for one, good luck! You can start from an index of 22,077. Also find and show up to the first twenty Derived S-W numbers which are prime and their index in the sequence.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Smarandache-Wellin primes step by step in the J programming language

Source code in the j programming language

   derive=. [: <:@#/.~ i.@10 , ]
   digits=. ;@:(<@("."0@":)"0)
      
   (#~ 1&p:) 10&#.@digits\ p: i. 10
2 23 2357

   (#~ 1 p: {:"1) (# , 10x&#.@digits@derive@digits)\ p: i. 1200
  32                  4194123321127
  72                547233879626521
  73                547233979727521
 134           13672766322929571043
 225         3916856106393739943689
 303       462696313560586013558131
 309       532727113760586013758133
 363      6430314317473636515467149
 462      8734722823685889120488197
 490      9035923128899919621189209
 495      9036023329699969621389211
 522   9337023533410210710923191219
 538  94374237357103109113243102223
 624 117416265406198131121272110263
 721 141459282456260193137317129313
 738 144466284461264224139325131317
 790 156483290479273277162351153339
 852 164518312512286294233375158359
1087 208614364610327343341589284471
1188 229667386663354357356628334581


  

You may also check:How to resolve the algorithm Show the epoch step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Tree from nesting levels step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Picat programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the Ruby programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the SNOBOL4 programming language