I am studying about Machine learning and how to use with chatbots, however I came across a problem:
How to group the possibilities of a numeric representation of a string, eg:
1 1 5 1 2 1
I'm trying to convert this to something like:
11 5 1 2 1
1 15 1 2 1
1 1 51 2 1
1 1 5 12 1
1 1 5 1 21
11 51 2 1
11 51 21
11 5 12 1
That is, test the possibilities, but without losing the order of the values (seria um fator linear ?)
.
I have tried in many ways, but I believe it is not in the correct logic, all the functions that I tried to create or found ready, follow the pattern of this:
function pc_permute($items, $perms = array( )) {
if (empty($items)) {
print join(' ', $perms) . "\n";
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems, $newperms);
}
}
}
print_r(pc_permute($ns));
Permutations - all possible sets of numbers
I have achieved the same result in several different ways, that is, I have achieved all possibilities, even if they shuffle the numbers, in my case I can not take advantage of it.
How could I find the possibilities of grouping an array without losing the natural order of the same array?
OBS:
The answer can be in a mathematical representation, then I could solve the problem.