Web Design and Web Development Forum

  1. #1
    Join Date
    Oct 2007
    Posts
    10
    Rep Power
    0
  2. BlueShift is on a distinguished road
  3. Simple Letter Combinations Program

    Hi,everyone i am new here,and i know very little about programming,and that is why i need your help.
    I need "Letter Combinations Program":for example we have 12 letters,and we need to make as manu as possible 5 letter words(each letter is used only once),and words can be meaningfull and unmeaningfull,which means that i need all combinations.How many combinations are there in this example an can some program be made in which these 12 letters are typed in and then the program list all possible 5 letter words(without repeating the same letter twice)?
    Reply With Quote Reply With Quote
  4. #2
    Stephen Bryant's Avatar
    Join Date
    Aug 2006
    Location
    North Carolina
    Age
    23
    Posts
    1,169
    Rep Power
    7
  5. Stephen Bryant is on a distinguished road
  6. Re: Simple Letter Combinations Program

    What language do you have to do this in? This sounds like a homework problem to me, and while we won't do it for you, we'll be glad to help.
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    Oct 2007
    Posts
    10
    Rep Power
    0
  8. BlueShift is on a distinguished road
  9. Re: Simple Letter Combinations Program

    It doesn't matter in which language it is done,i need this program for work belive it or not,i don't know anything about programming,so can you help me about this?:|
    Reply With Quote Reply With Quote
  10. #4
    Stephen Bryant's Avatar
    Join Date
    Aug 2006
    Location
    North Carolina
    Age
    23
    Posts
    1,169
    Rep Power
    7
  11. Stephen Bryant is on a distinguished road
  12. Re: Simple Letter Combinations Program

    Ok, this code will do it. It's written in PHP, you can view the result here: http://home.stephenbryant.net/nums.php

    PHP Code:
    <?php
    $x 
    = array('a','b','c','d','e');

    foreach (
    $x as $a) {
        foreach (
    $x as $b) {
            foreach (
    $x as $c) {
                foreach (
    $x as $d) {
                    foreach (
    $x as $e) {
                        echo 
    $a.$b.$c.$d.$e.'<br>';
                    }
                }
            }
        }
    }
    ?>
    Reply With Quote Reply With Quote
  13. #5
    Join Date
    Oct 2007
    Posts
    10
    Rep Power
    0
  14. BlueShift is on a distinguished road
  15. Re: Simple Letter Combinations Program

    Kyle,thank you very much for your response,this is very important for me,but this is not the solution i need.I don't need permutations.Twelve letters are given:a,b,c,d,e,f,g,h,i,j,k,f ,and i need all 5 letter words that can be made from these 12 letters,but each letter is used only once.DO have in mind that for the work in witch i need this program will always gave me diffrent letters(for example:q,r,y,h,f,b,c,z,j,a,o,j).Words can be meaningfull and unmeaningfull,which means that i need all combinations.

    Can you calculate for me how many possible words are there in this problem.

    Example: a,b,c,d,e,f,g,h,i,j,k,f

    abcde
    abcdf
    abcdg...

    ...fhijk
    Reply With Quote Reply With Quote
  16. #6
    Stephen Bryant's Avatar
    Join Date
    Aug 2006
    Location
    North Carolina
    Age
    23
    Posts
    1,169
    Rep Power
    7
  17. Stephen Bryant is on a distinguished road
  18. Re: Simple Letter Combinations Program

    Ok, this code will do that, example is in same place.
    PHP Code:
    <?php
    $x 
    = array('a','b','c','d','e','f','g','h','i','j','k','l');

    foreach (
    $x as $a) {
        foreach (
    $x as $b) {
            foreach (
    $x as $c) {
                foreach (
    $x as $d) {
                    foreach (
    $x as $e) {
                        
    $res[] = array($a,$b,$c,$d,$e);
                    }
                }
            }
        }
    }
    $i 0;
    foreach (
    $res as $arr) {
        
    $arr array_unique($arr);
        if (
    count($arr) == 5) {
            echo 
    $arr[0].$arr[1].$arr[2].$arr[3].$arr[4].'<br>';
            
    $i++;
        }
    }
    echo 
    $i;
    ?>
    The total is at the bottom.
    Last edited by Stephen Bryant; 10-03-2007 at 03:50 PM.
    Reply With Quote Reply With Quote
  19. #7
    Join Date
    Oct 2007
    Posts
    10
    Rep Power
    0
  20. BlueShift is on a distinguished road
  21. Re: Simple Letter Combinations Program

    Yes this is what i am looking for,thank you,but this is only an example.I want to change the letters so i can use it again and again.In which program do i run this php code so i can get the list of words.I presume that the only thing that i need to change is "$x = array('a','b','c','d','e','f','g','h','i','j','k','l');-instead of these letters i should type in other letters,ore there is more things that need to be changed.




    "
    Reply With Quote Reply With Quote
  22. #8
    hot_cakes's Avatar
    Join Date
    Aug 2005
    Location
    Bristol, UK
    Age
    30
    Posts
    2,913
    Rep Power
    9
  23. hot_cakes will become famous soon enough
  24. Re: Simple Letter Combinations Program

    Do you need a list of words, or the number of words that exist? If you only need the number, you don't need a computer program to work it out. That mathematics is relatively simple.

    And do these words have to be real (i.e. appear in a dictionary?)

    Edd
    Visit me at: mr-edd.co.uk
    Languages: Python | Lua
    Compilers: MinGW | MSVC++9
    Libraries: Boost | gtkmm
    Reference: Dinkumware | a.c.l.l.c-c++ FAQ
    Reply With Quote Reply With Quote
  25. #9
    Join Date
    Oct 2007
    Posts
    10
    Rep Power
    0
  26. BlueShift is on a distinguished road
  27. Re: Simple Letter Combinations Program

    I need a list of words,and these words doesnt have to be real.All i want is simple program where i type in 12 different letters and it list me all 5 letter words.
    Reply With Quote Reply With Quote
  28. #10
    hot_cakes's Avatar
    Join Date
    Aug 2005
    Location
    Bristol, UK
    Age
    30
    Posts
    2,913
    Rep Power
    9
  29. hot_cakes will become famous soon enough
  30. Re: Simple Letter Combinations Program

    What if a letter is duplicated? Do you want repeats in this case?
    Visit me at: mr-edd.co.uk
    Languages: Python | Lua
    Compilers: MinGW | MSVC++9
    Libraries: Boost | gtkmm
    Reference: Dinkumware | a.c.l.l.c-c++ FAQ
    Reply With Quote Reply With Quote

Similar Threads

  1. Instant Hacking (An Introduction to Python) Part 1
    By jacotyco in forum Articles, Tutorials, and Guides
    Replies: 3
    Last Post: 01-30-2007, 10:35 AM
  2. Java: Simple Paint Program
    By Jacyx in forum Articles, Tutorials, and Guides
    Replies: 0
    Last Post: 10-29-2006, 03:09 AM
  3. Noob here, help with this simple program?
    By RuSty in forum C and C++ Programming
    Replies: 14
    Last Post: 06-24-2006, 01:03 PM
  4. Timer exercise
    By Jeriko Yepez in forum C and C++ Programming
    Replies: 9
    Last Post: 03-06-2006, 05:29 PM
  5. what does this mean --> cc++/Socket.h???
    By AsianCutie in forum C and C++ Programming
    Replies: 15
    Last Post: 06-27-2005, 12:47 AM