Home Answers Viewqa PHP all combination via recursive function

 
 


Manjeet Sharma
all combination via recursive function
1 Answer(s)      a year and a month 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

View Answers

September 24, 2012 at 6:22 PM


can anyone write recursive function for generating alphanumeric string ?









Related Pages:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Load function ***PLEASE HELP
Load function ***PLEASE HELP   Hi I am writing a program that tracks... function that loads a file. The save function prompts the user to enter... a load function that prompts the user for the file name to be loaded
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
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
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
HTML combination of frames
HTML combination of frames  How do I specify a specific combination of frames instead of the default document
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
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
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
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
Car Music Streaming via iPhone Bluetooth, iphone Bluetooth Audio Streaming
device then all you need to listen to your favourite iPhone music is to press
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
Creating all combinations
Creating all combinations  hello, i want a script that can generate all the all words from given alphabets for example if i have three alphabets... abc cab bac acb i mean all the possible combinations so please help me
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  
ALL command - SQL
ALL Command in Java & SQL  Nee all commands in Java.  Dear Manoj, I didn't get u what do u mean by all command. could u please... possible options include: -g Generate all
Function of control unit in the CPU
Function of control unit in the CPU  Function of control unit in the CPU is - 1. To decode program instructions, 2. To transfer data to primary storage, 3. To perform logical operations, 4. To store program instructions, 5. All
xml to html via java
xml to html via java  how to read xml into html using java code
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
The $_GET Function
The $_GET Function The $_GET function in PHP is used to gather data of form submit with method="get". The data sent using get method is visible...;/form> Fetching form data sent via GET method You can fetch value
The $_POST Function
The $_POST Function The $_POST function in PHP is used to gather data of form...;/form> Fetching form data sent via POST method You can fetch data... built-in $_REQUEST function. $_REQUEST Method is used to collect form data
Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination.
administrator, or any combination. Prev Chapter 13. ... combination. Bean Provider's responsibility.... The Bean Provider must DECLARE all the environment entries accessed from
Append Function in Java
Append Function in Java  What is the use of append function in java? How to use the append function to append a string to a buffer string. Thanks... the string. This is very efficient method of appending string in Java. Once all
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
PHP Variable Outside Function
global variable inside the function, that means it all references to either...PHP Variable Outside Function In PHP Functions, a variable can be called either outside the function or inside the function. If we declare a variable within
Java replace all non alphanumeric
Java replace all non alphanumeric  Hi, In Java how to replace all... all non alphanumeric. Thanks   Hi, You can use the replaceAll() function of String class in Java. We will use the regular expression "[^a-zA-Z0-9
function
function  difference between function overloading and operator overloading
important for all final years student
important for all final years student   i need a java program for my... a file it should add page number in all pages after that delete all common letters... some inbuilt function with control flow conditions.. pls urgent so that only i
important for all final years student
important for all final years student  i need a java program for my... a file it should add page number in all pages after that delete all common words... it in simple java code meanwhile using some inbuilt function with control flow conditions
important for all final years student
important for all final years student  i need a java program for my... a file it should add page number in all pages after that delete all common words... it in simple java code meanwhile using some inbuilt function with control flow conditions
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
Algorithms: Recursive Binary Search
Java Notes: Algorithms: Recursive Binary Search Recursive Binary Search... recursive method calls instead of loops. However the iterative version... a tree, are better solved recursively because the recursive solution is so clear
function call in javascript - Java Beginners
function call in javascript  hi all, i've written a javascript , but i m unable to call a function getExpression.i dont know why getExpression function is not being called. heres my code : function

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.