Home Answers Viewqa PHP Creating all combinations

 
 


Manjeet Sharma
Creating all combinations
4 Answer(s)      a year and 2 months ago
Posted in : PHP

hello,

i want a script that can generate all the all words from given alphabets

for example

if i have three alphabets A,B,C

then a script that will generate the words as like below

a b

ab

bc

ca

ac

abc

cab

bac

acb

i mean all the possible combinations

so please help me in this

thanks

View Answers

April 9, 2012 at 11:17 AM


import java.util.*;

public class PermutationExample {
    public static void main(String args[]) throws Exception {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter String: ");
        String chars = input.next();
        showPattern("", chars);
    }

    public static void showPattern(String st, String chars) {
        if (chars.length() <= 1)
            System.out.println(st + chars);
        else
            for (int i = 0; i < chars.length(); i++) {
                try {
                    String newString = chars.substring(0, i)
                            + chars.substring(i + 1);
                    showPattern(st + chars.charAt(i), newString);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
    }
}

April 9, 2012 at 11:18 AM


function permute($str,$i,$n) {
   if ($i == $n)
       print "$str\n";
   else {
        for ($j = $i; $j < $n; $j++) {
          swap($str,$i,$j);
          permute($str, $i+1, $n);
          swap($str,$i,$j);
       }
   }
}

function swap(&$str,$i,$j) {
    $temp = $str[$i];
    $str[$i] = $str[$j];
    $str[$j] = $temp;
}   

$str = "hey";
permute($str,0,strlen($str));

April 9, 2012 at 11:19 AM


$string = "ABC";  
$strings = explode(' ', $string);

print_r(concat($strings, ""));

function concat(array $array, $base_string) {

    $results = array();
    $count = count($array);
    $b = 0;
    foreach ($array as $key => $elem){
        $new_string = $base_string . " " . $elem;
        $results[] = $new_string;
        $new_array = $array;

        unset($new_array[$key]);

        $results = array_merge($results, concat ($new_array, $new_string));

    }
    return $results;
}

April 9, 2012 at 7:52 PM


function permute($str,$i,$n) {
   if ($i == $n)
       print "$str\n";
   else {
        for ($j = $i; $j < $n; $j++) {
          swap($str,$i,$j);
          permute($str, $i+1, $n);
          swap($str,$i,$j);
       }
   }
}

function swap(&$str,$i,$j) {
    $temp = $str[$i];
    $str[$i] = $str[$j];
    $str[$j] = $temp;
}   

$str = "hey";
permute($str,0,strlen($str));

this helps me but there is problem

when i type string hey it generates only this result

(hey hye ehy eyh yeh yhe)

but i want in this way

y

e

h

ye

he

ey

eh

eyh

yeh

hey

i mean all possible worlds that i can make from the given alphabets

these generated words must contain

all single abphabets

all combibation two alphabets

and all combination from three alphabets

i want this script in php

thank









Related Pages:
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
generating unique combinations of length of x in a string of length l
generating unique combinations of length of x in a string of length l   Generating unique combinations of length of x in a string of length l? Suppose a string abcd in read from the console and we have to produce all unique
Creating Views
Creating Views Struts provides their own JSP tag library for creating view... contains all the basic html tag to create a page. Consider the simple page written... data by model and handle them appropriately. For creating a view you should
Creating Exception
Creating Exception  class Myexception extends Exception{ private int detail; Myexecption(int a){ detail=a; } public String toString(){ return...){ System.out.println("Caught"+e); } } } hi to all please help me friends here i created my own
Creating a Frame
, calender, combobox checkbox and many more for creating GUI in Java based... with your applet. Swing libraries is used for creating desktop applications...; Creating a Frame     
Open Source JavaScript
characters can be rearranged. If desired, it will display all of the combinations. These scripts all relate to time and dates. Some of them display only the month... code is available for all the scripts.     What
Dynamically creating a form in gwt?
Dynamically creating a form in gwt?  how can i create a gwt form by retrieving fields dynamically from a map? i have all the fields set in the data... fields in a map and creating a form with them
creating java classes
creating java classes  Create a Java class that can be used to store... that shows all of the information that you have stored in the object Create a program that tests your class by creating and using at least two objects of the class
Creating Dynamic Tree
Creating Dynamic Tree   Creating Dynamic Tree: I have to build a tree structure with the following data lets say that with this data childId parentId 1 - 0 (lets say this is root) 2 - 1 3 - 1 4 - 3 5 - 3 6 - 5 7 - 6 all I need
Creating Menu - MobileApplications
Creating Menu  Hi all, I am developing an application for nokia mobiles and other java enabled phones. I have downloaded the NetBeans IDE and JDK 1.5 with Wireless toolkit and was able to create a simple application
creating a file in a directory
creating a file in a directory  hi i have tried all the file methods to create a file inside a directory but none of them r working some of them are new File ( ".", "C:/fileInRoot.txt" ) new File ( "myDir", "/otherDir" ) File
Creating an exe file
Creating an exe file  Hi All, I have developed java application using swing by Net Beans IDE. Now I need to convert my application into exe file to run a application without intervention of Net Beans IDE. How to convert
Creating Database - SQL
Creating Database  Hi I am Guru I am having the confusion in creating the database.Actually Just I joined one small company. I am... ciao.co.uk. we are creating the database in mysql. 1> category->subcategory->
creating windows service - RMI
creating windows service  Hi, I have created a project using spring RMI and have some server.jar file which contians all the classes of server and server.exe file which is used to start the server. But I want to create a windows
creating web services - WebSevices
creating web services  Actually i am new for web services so Plz tell...:/Eclipse3.2/ Install Lamboz 3.2 (lomboz-all-in-one-R-3.2.2-200706042126-win32) D... stopped publish Window II. Steps for Creating Web Service 1.Create a new Dynamic
how to do combinations in java - Java Beginners
how to do combinations in java  i have 2 arrayLists. i want do the combinations using those 2 lists. example: ArrayList a contains action,when,c1_p2,and arrayList b contains c1_p1,or, c2_p2,c3-p1,or,c4_p2 output is action
creating a friendly url for web application
creating a friendly url for web application  Hi all, I don't know how to create a friendly url for a web application. Please help me to resolve this problem. Thanks, Suresh
Creating Database Tables and Indexes
Creating Database Tables and Indexes       In this section you will learn about describing... in identifier names then the maximum length will depend on the byte count of all
creating a feedback form - JSP-Servlet
creating a feedback form  hi, first of all thank you very much... i am refining this problem as follows: i am creating a feedback form... completes all the selection of radio buttons and he clicks on the SUBMIT FEEDBACK
remove all objects from NSMutablearray
remove all objects from NSMutablearray  Hi, How to remove all objects from nsmutablearray? Thanks   HI, Here is the code for creating NSMutablearray, adding objects and then removing all the objects: NSMutableArray
creating an applet for student management system
creating an applet for student management system  Write an applet/awt application which displays the interface for the program described below. When... all fields not visible or gray it out. In the interface appropriately use
creating class and methods - Java Beginners
creating class and methods  Create a class Computer that stores... for all above details from the user and calls method to check validity of Quantity and Price values. If all values are valid then create the objects and display
Creating Composite Widgets using GWT
Creating Composite Widgets using GWT       This example describes the Basics for creating.... VerticalPanel panel = new VerticalPanel() Creating a Vertical panel named
creating index for xml files - XML
creating index for xml files  I would like to create an index file...: smith 23 USA john 25 USA ... ... All xml files in the directory have... to use to get all files from a directory and read them and create index. And can
how to print all possible combination that sum to zero??
. Print all possible combinations that sum to zero Example Enter a num : 7 1...how to print all possible combination that sum to zero??  Ã?Â... each of the digits so that the resultant sum is zero. Print all posible
Right Way of Creating an Article Outline
Right Way of Creating an Article Outline   ... should firstly begin with the method of creating an article outline... such as creating introduction, writing the article body or concluding the article
Creating Message in JSON with JavaScript
Creating Message in JSON with JavaScript... about the JSON in JavaScript's some basic concepts of creating a simple object and creating an array of objects. Now we are going to discuss how to create
creating a java bean application - IDE Questions
creating a java bean application  hi, i want to create a java bean using BDK. please tell me all the steps for creating a simple java bean application. i have also a confusion about the properties of java bean. please explain
Need some help creating an order form.
Need some help creating an order form.  Hi there. I am looking... found on the form html page are useful. My question is: can I tie them all together on one page, have them submited all at once to my email and how would I
Creating Volume Bar Using Gauge Class
Creating Volume Bar Using Gauge Class       This example is all about creating a volume bar using Gauge class. We are creating the object of Gauge class that contains
do the combinations in java, pls help me its urhent - Development process
do the combinations in java, pls help me its urhent  import java.util.*; interface Expression { public void interpret(ArrayList exp); } class OrExpression implements Expression { public void interpret(ArrayList exp
Creating Composite Widgets using GWT
Creating Composite Widgets using GWT       This example describes the Basics for creating.... VerticalPanel panel = new VerticalPanel() Creating a Vertical panel named
Creating Data Access Object (DAO) Design Pattern
Creating Data Access Object (DAO) Design Pattern Data Access Object is the import component of the design patter of java. It provides a technique to separating the object persistence and data access logic. All the basic data access
need help creating a lift program - Java Beginners
need help creating a lift program  Classes, Methods, Constructors please i need help to create an elevator program Simulating an Elevator write..., ensuring that all your Elevator methods work successfully. then add two constructors
Creating a Web Application with the JSF Framework
Creating a Web Application with the JSF Framework... illustrates how to add JSF supporting file while creating a new web application... all behavior of JSF component in your application.       
Creating a web service that connects to the database - WebSevices
Creating a web service that connects to the database  Hello, Good work you are doing helping out those new to the field. Keep it up! I have... it quite literally and went through all the processes and procedures. However I
Site Map - All java tutorials
Site Map - All java tutorials In this section of sitemap we have listed all the important sections of java tutorials. Select the topics you want..., Spring, SQL, JSF and XML Tutorials.   These All Java Tutorials links
Creating, getting, and setting content using jQuery
Creating, getting, and setting content using jQuery       Creating, getting, and setting...-container'> .html('<p>All new content. <em>You bet
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI  Hi all, I am new to JNI. I am having a dll file created by somebody else. In this file, some c++ classes and functions are available. How can we create
Probem while creating PDF through JSP-Servlet - JSP-Servlet
Probem while creating PDF through JSP-Servlet  Hi, I have a web-app in which I want to convert MS-Office documents to PDF online. I'm using... pdf contains all the byte code and not the actual information contained
Creating Website with the use of template in Wicket
Creating Website with the use of template in Wicket...;creating Ajax Auto Completer" and some others very beautiful examples now... a website by creating templates of it. In this section of Wicket tutorial we
Creating an Encyclopedia using Java & mySQL 5 - Java Beginners
Creating an Encyclopedia using Java & mySQL 5  Dear Editor, I'm... searches and the number of searches made on them. 4. You shall validate all.... Please try again? 5. All searches and statistics should be updated
Java Applet - Creating First Applet Example
Java Applet - Creating First Applet Example       Introduction First of all we will know about the applet. An applet is a program written in java programming language
MySQL Creating and Deleting Database
MySQL Creating and Deleting Database   ... creating a database firstly check the currently existing database in the server... you don't have the privilege for.  Creating And Selecting a Database
Creating a Preference Node
Creating a Preference Node   ... exportSubtree()  which emits an XML document representing all of the preferences contained in the node and all of its descendants on the console. Here is the code
Creating Hyperlink using GWT
Creating Hyperlink using GWT     ...;Delhi") Creating Hyperlink object named 'link0'. Hyperlink is a class... VerticalPanel() Creating Vertical panel. Vertical panel  is a class that lays
Creating a JTable Component
Creating a JTable Component     ..., the procedure for creating a JTable component is given with the brief description... of three dimensional objects. Table model: All tables contains of  its data from
Creating a Database Table
Creating a Database Table     ... of database (DB) that has number of rows and columns. All tables are stored... are going to establish the connection with database and creating a table
to creating a registration form
to creating a registration form  how to create a registration form