A Prime Number Puzzle
November 28, 2014
Today’s exercise comes from the world of recreational mathematics.
For each number n from 1 to 9 inclusive, find a number m that begins with the digit n, has n digits, has each two-digit sequence within m a different prime number, and is as small as possible.
When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
In Python. Can be easily solved with greed.
Excuse me for the numbers, hilite.me does not format very well for pp…
And it would be great if we could edit our comments.
Haskell:
I guess using >>= to generate partial permutations would lead to a shorter solution, but after a bit of fiddling I manage to do it.
Once again, wrong format :s
Once you write down all the 2-digit primes, it is clear that the problem is simple enough to do manually in less time than it would take to write a program. Nevertheless, here’s a recursive Python solution:
@Paul ,@Francesco Can you solve this problem in C++,please? Thank you.