Created
June 27, 2014 04:12
-
-
Save allada/faf7cf7ebb2cb07eca8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function findset($s, $l){ | |
$len = count($s); | |
$outAry = array(); | |
$ptrs = array(); | |
for($i=0;$i<$l;$i++){ | |
$ptrs[] = $i; | |
} | |
$i=0; | |
$curPtr = $l-1; | |
while($ptrs[0] < $len - $l + 1){ | |
foreach($ptrs as $j => $pt){ | |
$outAry[$i][$j] = $s[$pt]; | |
} | |
if($ptrs[$curPtr]+1 < $len-$curPtr){ | |
$ptrs[$curPtr]++; | |
}else{ | |
// go back to find where new pointer can start again | |
for($j=$curPtr-1;$j>=0;$j--){ | |
if($ptrs[$j] < $len - 1 - $j){ | |
$curPtr = $j; | |
break; | |
} | |
} | |
$ptrs[$curPtr]++; | |
$curPtr++; | |
for($j=$curPtr;$j<$l;$j++){ | |
$ptrs[$j]=$ptrs[$j-1]+1; | |
} | |
} | |
$i++; | |
}; | |
return $outAry; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment