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 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 Tutorials/Questions & Answers:
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
Advertisements
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 an Applet
Creating an Applet  Hi, I have get a task regarding Creating an Applet using all Layout Manager, can anyone help me in this regard. I donā??t know..., first of all you should know about what is applet and then you should focus on how
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 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     
Creating a memory leak with Java
Creating a memory leak with Java  Creating a memory leak with Java
how to make combinations - Development process
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
to creating a registration form
to creating a registration form  how to create a registration form
creating windo chat
creating windo chat   hi ... please could you help me in creating chat aprograme in java ???? with comments beside codes please
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 URL in java
Creating URL in java  Hii to all I m trying to create a url using java. Address is http://www.merchant.com/pg/index.html When i m going to run...[] args) { try { // // Creating
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 circle inside a circle
Creating circle inside a circle  hi can any one give code for following output by awt/swing creating circle inside a circle ,outside cirlce and intersect a circle
Creating PDF in JAVA
Creating PDF in JAVA  How create pdf in java ? Take value from database for particular PDF
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 inheritance of cars
creating inheritance of cars   hi ... please help me in creating inheritance between some types of cars like car that is parent and both of private car and public car are extends it then bus and truck extends public car
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
creating reports in java
creating reports in java  how to create reports automatically in java and send it via mail by scheduling tine for weekly,monthly basis
Creating a setup file
Creating a setup file  How to create a setup file in tomcat as done in visual studio... could plz tell me as early as possible
creating JD ialog
creating JD ialog   hi ... please help me in creatin a JDialog box that contains two buttons of minimization and exit
Creating topic in Apache Kafka
Creating topic in Apache Kafka  Hi, What is command for creating topic in Apache Kafka? Thanks   Hi, In Kafka message are grouped... is command for creating topic from command line: bin/kafka-topics.sh --create
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
creating trafficsignal using thread
creating trafficsignal using thread  please give me code how to create trafic signal using thread and give me it to my email [email protected] thanks
creating dropdown lists in jsp
creating dropdown lists in jsp  i want to create two dropdown list which are dependent that is the first box choice have to evaluate the second boxs options
creating JAR - Java Beginners
creating JAR  I am beginner in J2ee.I am creating an application in Eclipse.I have created a javaproject and web project in the eclipse.I have installed SQL and Tomcat.I created a JAR of my java project and included
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 tables - IDE Questions
Creating tables  can i get a code that displays 10 records per page from a table student and when i click on the next button it displays the next 10 pages and so on, i'm using vb.net and sql database
creating pop up menu
creating pop up menu   how to create a pop up menu when a link in html page is clicked using jquery? and the link should be a text file   Please visit the following links: http://www.roseindia.net/tutorial/jquery
creating a global variable with php
creating a global variable with php  Is it possible to create a variable to declare as global in case of database connectivity?   Yes, if you want to have access of that variable anywhere in the program. See the example
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
creating hyperlinks in applet - Applet
creating hyperlinks in applet  Dear sir, how can i move from one applet to another applet and how can i use previous applet input data in anotherapplet(just like session tracking) thanks
Creating files of PDF's thumnails
Creating files of PDF's thumnails  Hi, How to create PDF's thumbnail in PHP? Thanks   Hi, You should have ImageMagick support on your server. You can then use following code to create PDF thumbnail image. <?php
Sql Connection is not creating
it is creating sql connection and allwoing me to access excel but when i am
creating packages in java
creating packages in java  Hi everybody, I am Rupesh Narayan, i faces a problem while creating package in core java. I write two programs that are described below:- 1.PackageDemo.java package javaclass; import java.io.*; public
Creating a service - JSP-Servlet
Creating a service  I created a database for username and password nd verify them for that I created a loginJSP page, using servlet I am getting username and password and perform validation and display the result back in jsp
creating a own interceptor - Struts
creating a own interceptor   i want to create own interceptor how i will create and which class i want implement  Hi friend, Interceptors: An intercept is a method used to intercept a business method
Creating Multiple ArrayList
Creating Multiple ArrayList   I want to create multiple ArrayList . import java.util.*; class ArrayListNames{ public static void main(String args[]){ //here i want to create 10 arraylists of type string
Creating Cursors in SQL
Creating Cursors in SQL       Creating Cursor in SQL is used to create a cursor in SQL... an example from Creating Cursor in SQL. To understand it, we create a table
creating Xml - Java Beginners
creating Xml  how we can create a xml file using java Creating XML... object. Creating XML File is possible  Creating XML File is possible... by Element Object.4. Appeng this Elemnts to DOcumnet object.  Creating XML
creating web services - WebSevices
creating web services  Actually i am new for web services so Plz tell.../ Install Lamboz 3.2 (lomboz-all-in-one-R-3.2.2-200706042126-win32) D:/Lamboz3.2... stopped publish WindowADS_TO_REPLACE_11 II. Steps for Creating Web Service
creating document in XML - XML
creating document in XML  Create an XML document for catalogue of Computer Science Book in a Library.   Hi friend, Code to help in solving the problem : import java.io.*; import
creating dynamic buttons in iphone
creating dynamic buttons in iphone  i Have a UIView and i wanted to create a multiple buttons to that should come on view load. It will be great if that can be removed after sometime or required time.   -(void

Ads