Search
 
SCRIPT & CODE EXAMPLE
 

PHP

permutation and combination program in php

<?php 
// PHP program to print all 
// permutations of a given string. 
  
  
/** 
* permutation function 
* @param str string to 
* calculate permutation for 
* @param l starting index 
* @param r end index 
*/
function permute($str, $l, $r) 
{ 
    if ($l == $r) 
        echo $str. "
"; 
    else
    { 
        for ($i = $l; $i <= $r; $i++) 
        { 
            $str = swap($str, $l, $i); 
            permute($str, $l + 1, $r); 
            $str = swap($str, $l, $i); 
        } 
    } 
} 
  
/** 
* Swap Characters at position 
* @param a string value 
* @param i position 1 
* @param j position 2 
* @return swapped string 
*/
function swap($a, $i, $j) 
{ 
    $temp; 
    $charArray = str_split($a); 
    $temp = $charArray[$i] ; 
    $charArray[$i] = $charArray[$j]; 
    $charArray[$j] = $temp; 
    return implode($charArray); 
} 
  
// Driver Code 
$str = "ABC"; 
$n = strlen($str); 
permute($str, 0, $n - 1); 
  
// This code is contributed by mits. 
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php increment variable 
Php :: append single quote around variable in php string 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://D:/Program Files/Composer - PHP/composer.phar/src/Composer/DependencyResolver/Solver.php on line 223 
Php :: Laravel SPA cors 
Php :: trova corrispondenza nella stringa php 
Php :: php huruf besar di awal 
Php :: php remove non printable characters 
Php :: comment blade php 
Php :: sqlsrv select 
Php :: ./yii serve not working in advanced template 
Php :: install composer laravel 
Php :: audio validation in jquery validation 
Php :: windows list registered applications 
Php :: php set cookie for 5 second 
Php :: php get referrer ajax 
Php :: php artisan preset bootstrap 
Php :: laravel collection every 
Php :: php trait example 
Php :: log php 
Php :: barcode for laravel 
Php :: send mail infinityfree phpmailer 
Php :: php fpdf in phpmailer 
Php :: php update sql database from form 
Php :: how to re assign value of associative array after assign in php 
Php :: laravel schedule kernel code sample 
Php :: laravel collection nth method 
Php :: php get api 
Php :: laravel get route 
Php :: only get selected value from has many ralation laravel 
Php :: wp wordPress variables de session 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =