I'm having trouble doing backtracking and not sure if what I'm doing is backtracking exactly.
I have n amount of integers for my example it will be [5,6,7,8].
From those integers I need to find if a prime sequence exists and if it does display it.
The prime sequence for this example is 7,6,5,8 since 7+6=13 6+5=11 5+8=13
To get the answer I can go through each n and then try to see if its a prime sequence.
Starting at 5:
- 5,6[7,8]
- 5,6,7[8]
Since 7+8 isn't prime. Go onto next integer.
Since 5+7 isn't prime. Go onto next integer.
- 5,8,[6,7]
Since 8+6 or 8+7 isn't prime. You're done with 5.
Starting at 6:
- 6,5[7,8]
- 6,5,8[7]
Since 7+8 isn't prime. Go onto next integer.
- 6,7[5,8]
Since 7+5 or 7+8 isn't prime. Go onto next integer.
Since 6+8 isn't prime. You're done with 6.
Starting at 7:
- 7,6[5,8]
- 7,6,5[8]
- 7,6,5,8
End since you found the prime sequence.
So how can I do this problem with backtracking?