|
-
Oct 10th, 2012, 06:49 PM
#1
Thread Starter
Hyperactive Member
replacing sub strings in a loop with conditions in mind
Hi! I have a slightly weird code I have to work on and I am hoping someone can give me a hand with this. It is ok if your suggestion is in pseudo code or something other than PHP as long as I get to understand the concept.
The project is complex so I will only expose the part that really troubles me..
I have a huge array or strings. Each string is a series of numbers in a range from 1 to 8,,, and basically the array is comprised of 40320 permutations of the original sequence.
so among many others my strings can look something like this:
$string[0] = "8 6 7 4 2 3 5 1";
$string[1] = "8 6 7 4 2 5 1 3"
$string[2] = "6 5 1 3 2 7 8 4"
$string[3] = "6 5 1 3 2 8 4 7"
what I need to do is iterate through the array and place a DASH between all possible numbers that behave like lower to higher value pairs...
what I am saying is this
IF MY STRING IS
1 2 3 4
then all my possible dashed replacements would look like this
1-2 3-4
1 2-3 4
1 2 3-4
it is important to keep in mind that the same number can not be linked with a dash twice
for example, this is not an option
1-2-3-4
the idea is that if two digits are paired up they can not be paired up with another digit.
also... for this string
6 5 1 3 2 7 8 4
my results would be
6 5 1 3 2 7-8 4
but in a string
1 2 3 4 5 6 7 8
there would be many solutuons...
HELPP!!! (lol,, seriously,, I am completely messed with this)
Last edited by Deliriumxx; Oct 10th, 2012 at 07:05 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|