Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa PHP all combination via recursive function

Have Programming Question? Ask it here!
 
 
 


Manjeet Sharma
all combination via recursive function
1 Answer(s)      2 years and 4 months ago
Posted in : PHP


hello

i have a php scrpt which generates all possibilities fro a given string

recursive function is used in it. i have given its code below

$charset = "abcd";


$charset_length = strlen($charset);
define('MAX_LENGTH', 4);
function recurse($width, $position, $base_string) {
    global $charset, $charset_length;

    for ($i = 0; $i < $charset_length; ++$i) {
        if ($position  < $width - 1) {
            recurse($width, $position + 1, $base_string . $charset[$i]);
        }


$string = $base_string . $charset[$i] ;

echo "$string<br/>";

    }
}

recurse (MAX_LENGTH, 0, '');
?>

the output of given code is

aaaa
aaab
aaac
aaad
aaa
aaba
aabb
aabc
aabd
aab
aaca
aacb
aacc
aacd
aac
aada
aadb
aadc
aadd
aad
aa
abaa
abab
abac
abad
aba
abba
abbb
abbc
abbd
abb
abca
abcb
abcc
abcd
abc
abda
abdb
abdc
abdd
abd
ab
acaa
acab
acac
acad
aca
acba
acbb
acbc
acbd
acb
acca
accb
accc
accd
acc
acda
acdb
acdc
acdd
acd
ac
adaa
adab
adac
adad
ada
adba
adbb
adbc
adbd
adb
adca
adcb
adcc
adcd
adc
adda
addb
addc
addd
add
ad
a
baaa
baab
baac
baad
baa
baba
babb
babc
babd
bab
baca
bacb
bacc
bacd
bac
bada
badb
badc
badd
bad
ba
bbaa
bbab
bbac
bbad
bba
bbba
bbbb
bbbc
bbbd
bbb
bbca
bbcb
bbcc
bbcd
bbc
bbda
bbdb
bbdc
bbdd
bbd
bb
bcaa
bcab
bcac
bcad
bca
bcba
bcbb
bcbc
bcbd
bcb
bcca
bccb
bccc
bccd
bcc
bcda
bcdb
bcdc
bcdd
bcd
bc
bdaa
bdab
bdac
bdad
bda
bdba
bdbb
bdbc
bdbd
bdb
bdca
bdcb
bdcc
bdcd
bdc
bdda
bddb
bddc
bddd
bdd
bd
b
caaa
caab
caac
caad
caa
caba
cabb
cabc
cabd
cab
caca
cacb
cacc
cacd
cac
cada
cadb
cadc
cadd
cad
ca
cbaa
cbab
cbac
cbad
cba
cbba
cbbb
cbbc
cbbd
cbb
cbca
cbcb
cbcc
cbcd
cbc
cbda
cbdb
cbdc
cbdd
cbd
cb
ccaa
ccab
ccac
ccad
cca
ccba
ccbb
ccbc
ccbd
ccb
ccca
cccb
cccc
cccd
ccc
ccda
ccdb
ccdc
ccdd
ccd
cc
cdaa
cdab
cdac
cdad
cda
cdba
cdbb
cdbc
cdbd
cdb
cdca
cdcb
cdcc
cdcd
cdc
cdda
cddb
cddc
cddd
cdd
cd
c
daaa
daab
daac
daad
daa
daba
dabb
dabc
dabd
dab
daca
dacb
dacc
dacd
dac
dada
dadb
dadc
dadd
dad
da
dbaa
dbab
dbac
dbad
dba
dbba
dbbb
dbbc
dbbd
dbb
dbca
dbcb
dbcc
dbcd
dbc
dbda
dbdb
dbdc
dbdd
dbd
db
dcaa
dcab
dcac
dcad
dca
dcba
dcbb
dcbc
dcbd
dcb
dcca
dccb
dccc
dccd
dcc
dcda
dcdb
dcdc
dcdd
dcd
dc
ddaa
ddab
ddac
ddad
dda
ddba
ddbb
ddbc
ddbd
ddb
ddca
ddcb
ddcc
ddcd
ddc
ddda
dddb
dddc
dddd
ddd
dd
d

i mean it generates all possibilities from a string "abcd" now i want that this code generate result which must have the possibilites of minimum 3 characters and above

now i want that this code generates all possibilites having minimum three charters like aaa bbb aab acc add abd abc aaaa aaab aaad dabb. i mean the code must ommit all one or two charcter string (i.e., a aa b bb cd dc ......) from the result

how i do that please help


Advertisement
View Answers

September 24, 2012 at 6:22 PM


can anyone write recursive function for generating alphanumeric string ?



Related Tutorials/Questions & Answers:
all combination via recursive function
all combination via recursive function  hello i have a php scrpt which generates all possibilities fro a given string recursive function... = strlen($charset); define('MAX_LENGTH', 4); function recurse($width
how to print all possible combination that sum to zero??
how to print all possible combination that sum to zero??  ?.... Print all possible combinations that sum to zero Example Enter a num : 7 1... each of the digits so that the resultant sum is zero. Print all posible
Advertisements
How ro convert char into string using recursive function in c#??
How ro convert char into string using recursive function in c#??  This coding is for java...but i want this in c# How ro convert char into string using recursive function in c#?? char [] ch={'H','E','L','L','o'}; TO ans
recursive method
recursive method  Write a recursive method to add the first n terms of the series 1 + (1/2) - (1/3) + (1/4) - (1/5
Fibonacci (Recursive)
Fibonacci (Recursive)  I need to write a program for my AP CS class... to do: Assignment: 1.Write a recursive method that takes in a single integer (x.... Instructions: Use these sample run output values: Recursive Fibonacci: 0, 3, 11
PHP Array Merge Recursive
PHP Array Merge Recursive The PHP array_merge_recursive() function is same as the array_merge() function. It creates an array by appending each input array..._recursive() is that if two or more than two elements have the same key
PHP Array Replace Recursive
PHP Array Replace Recursive: PHP provides array_replace_recursive() function..._replace_recursive() replaces the values of first array with the same values from...() is:  General Format array array_replace_recursive(array
recursive fuction in java
recursive fuction in java  A class has a recursive method which return a boolean value. If a codition is fail & control goes to out of loop... method which call that recursive method
program a combination locker
program a combination locker  The program uses 5 JSpinners to set the combination of the locker. The JSpinners should have a default value of 5 and limitations of 1 to 9 by 1 The Reset JButton will reset all the JSpinners
javascript recursive - Java Beginners
recursive function This function is used to read dynamically read xml node names... PT001 Food PG001 Cake My recursive function...); createTreeView(yy); function createTreeView(pNode) { for(i=0;i
Recursive regex PHP - PHP
Recursive regex PHP  any one? that can send me the code of regular expression that checks other regular expression for its correctness.   Hi, Please check at http://www.roseindia.net/tutorial/php/phpbasics/PHP
HTML combination of frames
HTML combination of frames  How do I specify a specific combination of frames instead of the default document
java program on recursive method
java program on recursive method  in how many ways can you make change for one dollar(100 cents) using pennies(1-cent coins), nickels(5 cents), dimes(10 cents),and quarter(25 cents)? the coins must add up to the exact total
recursive - Java Beginners
recursive   Question Details: I need to write a recursive method that displays the lyrics of the song "Bingo". Verse 1: There was a farmer..., Clap, Clap, Clap, Clap) - Write a Java program to test your recursive
Mysql Lpad Function
Mysql Lpad Function       Mysql Lpad Function is used to add padding to the left end of the string. The Function stopped the combination of string and added padding if it reached
Mysql Lpad Function
of the string.The Function stopped the combination of string and added padding... Lpad Function:- The Query below return you the all the letters of roseindia.net... Mysql Lpad Function     
PHP Function
manageable, robust. A general format of the function in PHP is as follows: function <function name> (<list of parameters>) With the help of functions we can reduce time and effort, all we need to do is create a function
factorial using recursive
factorial using recursive  can please give this code !i am going to do a factorial function using recursion definition and then . my professor told me that we are going to create a three screen. the first screen should be input
xml to html via java
xml to html via java  how to read xml into html using java code
What’s the difference between accessing a class method via -> and via ::?
What?s the difference between accessing a class method via -> and via ::?  What?s the difference between accessing a class method via -> and via
Reading excel via JSP
Reading excel via JSP   The problem is while reading cells values which all are having "space" between the word, I can read only till space after that space the word has been dropped. for Example Name
Collect Mac Address Connected via Bluetooth
Collect Mac Address Connected via Bluetooth  How to collect automatically all mac address connected via bluetooth and save in a file
function
function  difference between function overloading and operator overloading
20 question Game involving recursive methods
20 question Game involving recursive methods  I have a problem with compiling my program. Any help please. My code of line where it says "Node... to base. { System.out.println("All your base
join multiple tables via hibernate criteria - Hibernate
join multiple tables via hibernate criteria  Dear all, i have a problem working with hibernate. i wanna join multiple tables via hibernate criteria. How can i do this operation? Thanks in advance regards Rosa
Accessing database with JDBC via Java
Accessing database with JDBC via Java  How to access a database with JDBC via Java application?   Accessing database with JDBC through... the connection. It frees all the resources occupied by the database. printStackTrace
OS service via bluetooth socket
OS service via bluetooth socket  through bluetooth socket i want to send instructions to the OS, where i dont want any server code for this on my PC or Laptop. My instructions should be handled by the OS inbuilt bluetooth
Jsp/java-script, spring combination problem
Jsp/java-script, spring combination problem   Hi Friends....... I am developing one application using jsp,spring,java script,hibernate,Pojo There is one Jsp form on that I want data as location and ward wise; There is two
A Java Program That Prints Out Result Via Printer
A Java Program That Prints Out Result Via Printer  A Java Program That Prints Out Result Through Printer Depending upon paper size , and print the calculated result on printer and save result as text file
PHP list all files
All files, directories of the given directory can be listed. function readdir() takes input as the directory handle. Then readdir() returns the name of all the files and directories. PHP List All Files Example <?php  
Doubt in using combination of JSP page and Java class. - JSP-Servlet
Doubt in using combination of JSP page and Java class.   I've got a drop down list and a table of 2 rows and 2 columns with a button in each cell... the data in form bean and used in jsp file.  Well first of all thank
Remember me on this computer (via cookies) in jsp servlet
Remember me on this computer (via cookies) in jsp servlet  Remember me on this computer (via cookies) in jsp servlet   Hi, Here is the detail of using cookies to identify the user. In Servlet or JSP you can set
PHP Function
function helps us a lot. A function is a set of coding within a block, which has... of functions we can reduce time and effort, all we need to do is create a function and put the necessary coding into it and we can call this function from
how to access element added via javascript dynamically using jsp code
how to access element added via javascript dynamically using jsp code  Urgent..Anyone please Assist how to access data from the elements added via... using javascript (by calling a below function on click event of button
I determine where a given table is referenced via foreign keys.
I determine where a given table is referenced via foreign keys.  How can I determine where a given table is referenced via foreign keys
insert arabic chacters in mysql via java - Java Interview Questions
insert arabic chacters in mysql via java  Dear, I have I java rpogram that I want to insert arabic letters in mysql. Do you have any idea about... in database"); // close all the connections. ps.close
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
Dialling from computer with other phone via modem card
Dialling from computer with other phone via modem card  Hello everyone I would like to create a c# desktop application that has ability to call a phone number through a modem connected in the computer. During research I ended up
function method
function method  i. void display(String str.int p)with one string argment and one integer argument. it display all the upper character if 'p' is 1(one)otherwise, display all the lowercase characters. ii. void display (String
PHP list all variables
PHP all declared and environment variables can be listed get_defined_vars() method returns all the variables in the form of array. The array returned is handles by the class ArrayObject class. Example of PHP List of all
isNaN function
isNaN function  What does isNaN function do
How to display data from database in a TableView via Hibernate
How to display data from database in a TableView via Hibernate  I... in JavaFx Scene Builder. So far the TableView does not change at all and only...</property> <!-- Echo all executed SQL to stdout -->
function addValue
function addValue  i have question about the javascript the function addvalue script is working to add some name but is not save on the html so please resolve my problem what can i do for addvalue function will be to save
function addValue
function addValue  i have question about the javascript the function addvalue script is working to add some name but is not save on the html so please resolve my problem what can i do for addvalue function will be to save
function addValue
function addValue  i have question about the javascript the function addvalue script is working to add some name but is not save on the html so please resolve my problem what can i do for addvalue function will be to save
If function in PHP
If function in PHP  Hi, Provide me the example of If function in PHP. Thanks   Hi, If function is PHP is used to check for some condition and the execute a block of code. He is an example of if() function in PHP
Calling a function
Calling a function  Hi, I have a function xyz() in php code. When a button is clicked it should execute that particular function for that i have... function function xyz() { } but this is not working can u tell me
function method
function method  input Rs. 12000 Discount= 10%, 8% = Rs.(12000-1200) = Rs.(10800-864) = Rs. 9936
function method
function method  input Rs. 12000 Discount= 10%, 8% = Rs.(12000-1200) = Rs.(10800-864) = Rs. 9936
Advertisements
 

 

 

DMCA.com