Results 1 to 9 of 9

All possible word combinations from letters .. ?

  1. #1
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168

    All possible word combinations from letters .. ?

    I have the following question. I would like to generate all the possible 4 letter word combinations from the below letters. I know .. this is supposed to be fun and get us thinking.



    I want to do it in Access .. as it is hard for me to compile something in C and I am a database guy. You know .. like one button click and done.

    I am thinking outputting the results to a table would be best and I can just go from there.

    To make things more interesting .. it must be as follows .. First Letter (M,D,B,N,L,J,P,R,T,S) 2nd Letter (O,Y,U,R,T,H,L,E,I,A) 3rd Letter (E,D,C,O,R,T,S,L,A,N) 4th Letter (Y,K,R,S,L,T,V,H,D,E)

    I am going to start simple .. with like 3 letters in each row and go from there as the logic should be the same.

    Thanks

  2. #2
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Ok .. here is my resulting database for your review. It was interesting .. I found some code that someone used before that was similar. I altered it to suit my needs. Please let me know if my logic / coding is flawed
    but it seems to give me the results I expected and no duplicated records with the expected number of records.

    The query .. will give you the results in alphabetical order. I have added a timer .. so you can see how fast your pc is. You know .. you wanted to, I know I did.

    GenerateWords.accdb

  3. #3
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    1,863
    Very interesting, but 10,000 SQL executions took a while to add all the words. I wondered how much faster a DAO .addnew would run, so I added routines to do it. The difference in speed is phenomenal - It takes less time to add 100,000 records via DAO than it takes to add 10,000 via SQL INSERT.
    See for yourself GenerateWordsSpeed.zip

  4. #4
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Thanks. That is funny .. I forgot that I did this, mind you it was sometime ago. I actually did it to see all the combinations for a combination lock that uses characters rather than numbers. It was just fun. I will definitely look at your file.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    13,798
    I saw this and thought there must be a simpler way. Cartesian Product came to mind.
    I am attaching the database (original from OP with my additional work).
    The approach I found was to create a table for each of the char positions in the 4 letter word.
    Then use a cartesian product on the 4 tables.

    Try it from form CartesianGenerate

    Result is: It generates the 10000 4 letter words in ~ 85 millisecs.
    Attached Files Attached Files

  6. #6
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Quote Originally Posted by orange View Post
    I saw this and thought there must be a simpler way. Cartesian Product came to mind.
    I am attaching the database (original from OP with my additional work).
    The approach I found was to create a table for each of the char positions in the 4 letter word.
    Then use a cartesian product on the 4 tables.

    Try it from form CartesianGenerate

    Result is: It generates the 10000 4 letter words in ~ 85 millisecs.
    As the OP .. that is just nothing more than impressive.

  7. #7
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    1,863
    That should be the last word for this thread. Hard to beat! My machine did it in 40ms.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    5,716
    Quote Originally Posted by edmscan View Post
    Thanks. That is funny .. I forgot that I did this, mind you it was sometime ago. I actually did it to see all the combinations for a combination lock that uses characters rather than numbers. It was just fun. I will definitely look at your file.
    Speaking from a statistics viewpoint the numbers used to open a "combination" lock are a set of permutations, not a set of combinations. The name of the object, and I suppose the what we call the set of numbers, is actually a misnomer.
    5, 10 15 is one combination of numbers. 10, 5, 15 is the same combination of numbers, although I grant it is not the same order when it comes to locks.
    Using the same 3 digits 5, 10, 15:
    5, 10, 15 is one permutation. The others are
    5, 15, 10
    10, 5, 15
    10, 15, 5
    15, 5, 10
    15, 10, 5
    If I haven't forgotten any, there are 6 permutations for 3 numbers taken 3 at a time.
    The number of combinations for the set (3 taken 3 at a time) is one.
    End of statistics 101.
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.
    Sometimes I talk to myself - like when I need expert advice.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    13,798
    Guys,

    Micron is quite correct and for "comprehensible" explanations of most Mathematics concepts I find this link
    very helpful.
    https://www.mathsisfun.com/combinato...mutations.html

    Re: The time to create the records. I'm using a Lenovo Z710 with I7 @ 2.4 Ghz.
    I ranges from ~71 to 85 milliseconds.

    Glad you liked the SQL (Cartesian Product) approach.

    orange

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Finding all possible combinations
    By fauowls in forum Access
    Replies: 3
    Last Post: 03-23-2013, 05:34 PM
  2. How to search for duplicate combinations
    By EvanRosenlieb in forum Access
    Replies: 5
    Last Post: 04-17-2012, 02:56 PM
  3. Calculating all possible combinations
    By Data in forum Queries
    Replies: 3
    Last Post: 06-20-2011, 03:02 PM
  4. Query for All Possible Combinations
    By Rawb in forum Queries
    Replies: 1
    Last Post: 10-09-2010, 08:33 PM
  5. ms access version combinations
    By marianne in forum Access
    Replies: 1
    Last Post: 08-05-2009, 07:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums