473,785 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Anagram a word

Hi,
Thanks for reading this. How do I list all possible permutations of a
word? I've figured out how to get all the characters in alphabetical order.
I then want to display every possible character permutation in sequence,
like so:
abcd abdc acbd acdb adbc adcb bacd badc bcad bcda bdac bdca cabd cadb cbad
cbda cdab cdba dabc dacb dbac dbca dcab dcba
This is turning out to be much more difficult than I thought it would
be. It seems to be that a recursive function or procedure, possibly using
the length of the string, might be a good idea... but since the number of
permutations is x!, where x is the length of the string, I don't quite know
where to begin. Can anybody give me some hints? Thanks!

Thanks,
Eric A. Johnson
Jul 17 '05 #1
1 5999
xyz
One way of generating all anagrams for a word systematically is to use
numbers of a base correspondiing to the number of characters in the
word. Then, assign a "digit" to each letter of the word. If you have
a 4-letter word you will use a base 4 counter which will have a range
from 0000 to 3333. Enumerate all members of the range: 0000, 0001,
0002, 0003, 0010, 0011, 0012, 0013, 0020, etc. Select only those
members which have all different digits. E.g, 0123 would be the
first one, then 0213, etc. For each of these selected members,
substitute the letters corresponding to the original word. Thus, for
"abcd", a=0, b=1, c=2, d=3. Taking the first member from our
enumeration with 4 different digits, (0123) becomes (abcd), (0213)
becomes (acbd), etc.

If the original word has non-unique letters, some of your anagrams
will be duplicated. This process is sytematic and complete, but not
very efficient because a lot of the numbers have to be discarded
because they don't have unique digits. Also, as your word length
increases, so does the length of the process. An 8-letter word would
require an 8-digit, base-8 counter.

If you want to find all anagrams of a word in a dictionary, there are
better ways of doing this using word lengths and hash codes based on
letter content.

Good luck,

xyz
==============

On Tue, 30 Sep 2003 23:47:38 GMT, "Eric A. Johnson"
<aj****@earthli nk.net> wrote:
Hi,
Thanks for reading this. How do I list all possible permutations of a
word? I've figured out how to get all the characters in alphabetical order.
I then want to display every possible character permutation in sequence,
like so:
abcd abdc acbd acdb adbc adcb bacd badc bcad bcda bdac bdca cabd cadb cbad
cbda cdab cdba dabc dacb dbac dbca dcab dcba
This is turning out to be much more difficult than I thought it would
be. It seems to be that a recursive function or procedure, possibly using
the length of the string, might be a good idea... but since the number of
permutations is x!, where x is the length of the string, I don't quite know
where to begin. Can anybody give me some hints? Thanks!

Thanks,
Eric A. Johnson


Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2291
by: DK15798 | last post by:
Anybody think there is a way to solve the anagram problem (reading in a dictionary of words and printing out the anagrams for all words) with an open address hash table as opposed to a chained hash table?
8
3538
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
4
12442
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
2
2589
by: jcollins1991 | last post by:
im trying to make a program thats supposed to check whether 2 strings are anagrams of each other (anagram = same letters in both strings, but in different orders... "cool as wet art" , and "cs at waterloo" for example). while (str2.get_Length() != 0) //<---- checks whether second string is "cleared" { //loop, from start of string (k = 0) to end of string (length2) for (k = 0; k <=...
1
2735
by: heloworld | last post by:
hi buddies.... i don ve any idea as how to solve an anagram problem... plz help me out....
0
1926
by: alivip | last post by:
I write code to get most frequent words in the file I won't to implement bigram probability by modifying the code to do the following: How can I get every Token (word) and PreviousToken(Previous word) and frequency and probability From text file and put each one in cell in table For example if the text file content is "Every man has a price. Every woman has a price." First Token(word) is "Every" PreviousToken(Previous...
5
2540
by: alivip | last post by:
How can I get every Token (word) and PreviousToken(Previous word) From multube files and frequency of each two word my code is trying to get all single word and double word (every Token (word) and PreviousToken(Previous word)) from multube files and get frequency of both. it can get for single word but double word give error line 50, in most_frequant_word word1+= ' ' + word_list IndexError: list index out of range import...
19
2804
by: dave | last post by:
Hi All, I wrote a program that takes a string sequence and finds all the words inside a text file (one word per line) and prints them: def anagfind(letters): #find anagrams of these letters fin = open('text.txt') #one word per line file wordbox = #this is where the words will go for line in fin: word = line.strip()
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.