Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: PHP  |  size: 0.55 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. set_time_limit(0);
  3. function permute($str){
  4.         if(strlen($str)<2){
  5.                 return array($str);
  6.         }
  7.  
  8.         $permutations = array();
  9.         $tail = substr($str, 1);
  10.  
  11.         foreach(permute($tail) AS $permutation){
  12.                 $length = strlen($permutation);
  13.                 for ($i=0; $i<=$length; $i++){
  14.                         $permutations[] = substr($permutation, 0, $i) . $str[0] . substr($permutation, $i);
  15.                 }
  16.         }
  17.  
  18.         return $permutations;
  19. }
  20.  
  21. $permute = array_unique(permute("אבג דהוז"));
  22. foreach($permute AS $unq){
  23.         $a = substr($unq, 0, -4);
  24.         $b = substr($unq, -4, 4);
  25.         echo $a." ".$b."<br>";
  26. }
  27. ?>