Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible grouping of words
    primarykey
    data
    text
    <p>This is not homework: Came across this scenario while working on <a href="https://stackoverflow.com/questions/15141928/php-string-differences-and-dynamic-restrictions">PHP String Differences and Dynamic Restrictions</a></p> <p>Given a string of <code>n</code> words how to distribute them into <code>m</code> groups without altering the word sequence?</p> <pre><code>Example 1: String: "My name is SparKot" Groups: 2 (string is split in to two strings) Possible groups will be: ('My', 'name is SparKot'), ('My name', 'is SparKot'), ('My name is', 'SparKot') </code></pre> <p>with the same string</p> <pre><code>Example 2: String: "My name is SparKot" Groups: 3 (string will be split in to three strings) Possible groups will be: ('My', 'name', 'is SparKot'), ('My', 'name is', 'SparKot'), ('My name', 'is', 'SparKot') </code></pre> <p>My PHP function() with no direction(it is suppose to return Multi-dimension of groups):</p> <pre><code>function get_possible_groups ($orgWords, $groupCount, &amp;$status) { $words = explode (' ', $orgWords); $wordCount = count($words); if ($wordCount &lt; $groupCount) { $status = -1; return; } else if ($wordCount === $groupCount) { $status = 0; return (array_chunk($words, 1)); } for ($idx =0; $idx &lt; $wordCount; $idx) { for ($jdx =0; $jdx &lt; $groupCount; $jdx++) { } } // append all arrays to form multidimension array // return groupings[][] array } $status =0; $groupings = get_possible_groups('My name is SparKot', 4, $status); var_dump($groupings); </code></pre> <p>for above example-2 function is supposed to return:</p> <pre><code>$groupings = array ( array ('My', 'name', 'is SparKot'), array ('My', 'name is', 'SparKot'), array ('My name', 'is', 'SparKot')); </code></pre> <p>Any hints to approach this problem will be much appreciated.</p> <p>Progress:</p> <ul> <li>case: when <code>wordCount = groupCount</code> [solved]</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload