I’m trying to create a boolean recursive function which accepts 1 parameter only and doesn’t act as a wrapper for another function, that checks whether a number contains a pair of combinations which are both primes.
For example, the possible combinations for 8379 are:
8 379
83 79
837 9
I’ve managed to create the function using a wrapper function, but I can’t seem to be able to do it without a wrapper.
What I currently have is:
func(num):
num is prime -> return true
else -> call func(num / 10, num % 10).
fun(num1, num2):
num1 and num2 are primes -> return true
num1 < 10 -> return false
return func(num1 / 10, concat(num1 % 10, num2))
Writing in Java.
I’m not quite sure if you want to check for “multiple” combinations of the number or just one.
Here’s my recursive function for checking just one combination’s existence. If I addressed your requirement incorrectly, please leave a comment.
Invoke it using
splitPrime(n,10)