All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Peeling Primes (Posted on 2024-05-30) Difficulty: 3 of 5
The prime 1366733339 can be peeled down to a single digit by removing one digit at a time from either end to make a sequence of primes 136673333, 36673333, 3667333, 667333, 66733, 6673, 673, 67, 7.

Determine the largest integer for which this is possible.

No Solution Yet Submitted by K Sengupta    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Some Thoughts computer exploration Comment 3 of 3 |
The program builds rather than peels. It uses unsigned 64-bit integers so as to expand the allowable size without sacrificing speed, but even then it is slow and is possibly limited by the size of numbers it allows.   
   
clearvars
global p mx build 

mx=0;
for p=[2 3 5 7]
  build=uint64(p);
  addon
end

function addon
global p mx build 
for front=[true false]
  if front
    digset=uint64(1):9;
  else
    digset=uint64([1 3 7 9]);
  end
  for newdig=digset
    pSave=p; buildSave=build;
    if front
      % p=str2uint64([num2str(newdig) num2str(p)]);
      sss=['p=uint64(' num2str(newdig) num2str(p) ');'];
      eval(sss);
    else
      p=10*p+newdig;
    end
    if isprime(p)
      if p>=mx
        mx=p;
        disp(p)
        for i=length(build):-1:1
          disp(build(i))
        end
        % disp(' ')
      end
      build=[build p];
      addon;
    end
    p=pSave; build=buildSave;
  end
end
end

finds the following, which is near the limit of unsigned 64-bit integers:
   
      9813229623122317339
      813229623122317339
      81322962312231733
      1322962312231733
      322962312231733
      32296231223173
      3229623122317
      229623122317
      29623122317
      2962312231
      962312231
      62312231
      6231223
      231223
      31223
      1223
      223
      23
      2
      
Note that due to time constraints it only shows series build on the first prime, 2. It does however, as mentioned, get close to the limit of the variable type used.      

  Posted by Charlie on 2024-05-30 09:02:46
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (4)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information