A Prime Number Puzzle
November 28, 2014
First I made a list of all the two-digit primes; I didn’t need a program to do that, but you like you can see a simple program to compute the two-digit primes at http://programmingpraxis.codepad.org/YhAGquhp:
11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Then I solved the problem by hand. I didn’t count, but there are remarkably few places where there is actually a choice of what digit comes next, and if you work from 1 to 9 it is frequently possible to reuse all or part of a previous solution, so it took only a few minutes to solve the problem, certainly less time than it would take to write a program. Here’s my solution:
1: 1
2: 23
3: 311
4: 4113
5: 53113
6: 611317
7: 7113173
8: 83113717
9: 971131737
The lesson, of course, is that sometimes computers only muck up a simple problem with a complicated solution.
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.