I had fun solving this, so iI offer this golf challenge.
The objective of this golf is to find the largest prime number that can be constructed using the given instructions.
You should accept 3x3 grid of single digits as input. (It's uptoup to you, how you want to do that, but specify that in your program.)
You can move along the grid orthogonally (left,right right,up up or down), and as you move,you you keep appending the digits you walk across. Eg
E.g.
1 2 3
3 5 6
1 8 9
Say we start at 1
,
we can form the number 1236589 but cannot form 15.
You have to evaluate every starting position.
If a prime cannot be found, print -1
, else print the prime itself.
Shortest code wins, make sure it runs within 10secs10 secs.
Have Fun!
Edit: Use one position exactly once, in the entire number.
Here's a test case
Input:
1 2 3
4 5 6
7 8 9
Output: 69854123