Greetings.
I'm working on a program that will "descramble " words. Think of a word
scramble game where there is a list of characters, and several blank
spaces to denote the word(s) that you are to come up with from the list.
i.e.(* denotes a space): _ _ _ _ _ * _ _ _ _ _ _
characters: .hwodlelrlo
answer: hello world.
So, implemented as a c/c++ program, you would have something like:
<begin pseudo-c code>
char letters[11] = {'.','h','w','o ','d','l','e',' l','r','l','o'} ;
char PossibleWordOne[100][5];
char PossibleWordTwo[100][6];
//WordOneLength = 5;
//WordTwoLength = 6;
/* Ultimately, the goal is to not know the number of words or their
lengths or even the scrambled characters before execution, but this will
work for the example. I got the 100 because there should be no way of
getting more than 100 possible 'real' words*/
/* In order to make sure the combination of characters is a real word,
verify() will check it against a word list and return True or False Swap
will be a simple function (I hope it'll be simple anyways) that will swap
the characters into the next combination.*/
Permu()
{
static int counter = 1;
static int possibles = 0;
while (counter != 11!) /* Since there are 11! possible combinations */
if (!(Verify(Swap( letters*))
{ counter++;
Permu();
}
else
{
PossibleWordOne[possibles][] = letters*;
possibles++;
counter++;
Permu();
}
<end pseudo-c code>
Well, what do guys think? Any suggestions or sample code would be greatly
appreciated. In order to optimize performance, I would like to load the
word list directly into memory, and preferably have the words categorized
by length. This way, I can find the possible words for the longest word
first, and then go to the next longest. For example, let's say that I find
two possible combinations for the five-letter word. Then, I can seperate
them into two cases to find the four-letter word. Each case would have a
char array with 5 less chars than the original, which should make it a lot
faster to find the second word. Then let's say that only case two turns up
a possible combination for the four letter word. case one could then be
disguarded and you could move on to the next word... and on and on.
Anyways, that's what I've got so far... Like I said any suggestions would
be greatly appreciated.
Thanks,
Gaines 3 6015
"gdogg1587" <NO*********@SP AMearthlink.net > wrote in message
news:fb******** *************** *******@localho st.talkaboutpro gramming.com... Greetings.
I'm working on a program that will "descramble " words. Think of a word scramble game where there is a list of characters, and several blank spaces to denote the word(s) that you are to come up with from the list. i.e.(* denotes a space): _ _ _ _ _ * _ _ _ _ _ _
characters: .hwodlelrlo
answer: hello world.
So, implemented as a c/c++ program, you would have something like: <begin pseudo-c code> char letters[11] = {'.','h','w','o ','d','l','e',' l','r','l','o'} ;
char PossibleWordOne[100][5]; char PossibleWordTwo[100][6]; //WordOneLength = 5; //WordTwoLength = 6; /* Ultimately, the goal is to not know the number of words or their lengths or even the scrambled characters before execution, but this will work for the example. I got the 100 because there should be no way of getting more than 100 possible 'real' words*/
/* In order to make sure the combination of characters is a real word, verify() will check it against a word list and return True or False Swap will be a simple function (I hope it'll be simple anyways) that will swap the characters into the next combination.*/
Permu() { static int counter = 1; static int possibles = 0; while (counter != 11!) /* Since there are 11! possible combinations */ if (!(Verify(Swap( letters*)) { counter++; Permu(); } else { PossibleWordOne[possibles][] = letters*; possibles++; counter++; Permu(); }
<end pseudo-c code>
Well, what do guys think? Any suggestions or sample code would be greatly appreciated. In order to optimize performance, I would like to load the word list directly into memory, and preferably have the words categorized by length. This way, I can find the possible words for the longest word first, and then go to the next longest. For example, let's say that I find two possible combinations for the five-letter word. Then, I can seperate them into two cases to find the four-letter word. Each case would have a char array with 5 less chars than the original, which should make it a lot faster to find the second word. Then let's say that only case two turns up a possible combination for the four letter word. case one could then be disguarded and you could move on to the next word... and on and on. Anyways, that's what I've got so far... Like I said any suggestions would be greatly appreciated.
I've written a similar program before, just for a laugh. To determine the
"legal" words that one can make, there's a simple, efficient approach that
doesn't take too much time to implement. Simply scan the entire list of
"legal" words, testing if it is a subset of the scrambled letters. This
tends to be pretty quick (virtually instantaneous on my machine), as there
are only around 180,000 words in the English language. Then, for each word
you can make that is of an appropriate length, examine each pair (or
whatever size tuple) to see if, together, they "use up" all of the scrambled
letters. Of course, you may have multiple correct answers. For other
programs, it may pay to try to do something "smarter", but, in my
experience, nothing fancy is required for a program like this. However, it
might get out of hand if you had a lot of letters that could make many
words, and there are many words in the sentence.
--
David Hilsee
Hmm... That's a pretty good idea. 18,000 is a lot less than 11! And a whole
lot less than 100!. And, I could categorize the word list by length of word
to make it even faster! That's great! Thanks.
Hmm... That's a pretty good idea. 18,000 is a lot less than 11! And a whole
lot less than 100!. And, I could categorize the word list by length of word
to make it even faster! That's great! Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: The Roys |
last post by:
Hi
Im doing something wrong in quitting the Word.Application in my VB program.
I have
General Declarations
Dim AppWord As Word.Application
Form_Load()
Set AppWord = CreateObject("Word.Application")
|
by: Microsoft |
last post by:
I'm trying to display a word document inside a web page, but everytime I do
I get this error:
Error Type:
Microsoft VBScript runtime (0x800A0046)
Permission denied: 'CreateObject'
Does anybody know the correct way to do this? I don't want to link to a
document, but rather display a word file inside the asp page.
|
by: Greg Andora |
last post by:
Hello,
I've had an ASP page that worked for at the minimum for a year and now it is acting very odd and I need some help to fix it. What my page does/did is creates a Word.Application object and a new document from a template. It then proceeds to fill in a bunch of the information on the word document using bookmarks and data from a database. Then it saves the document to a directory and sends the user off to go get the new document.
...
|
by: MaxiWheat |
last post by:
Hi,
I am using a software that uses MS Word to create PDF files. When I try
to run the sample code (ASP 3.0), I get an error on this statement :
Set oWord = Server.CreateObject("Word.Application")
That error says :
The call to Server.CreateObject failed while checking permissions.
Access is denied to this object.
|
by: Petar Popara |
last post by:
I did everything as Kevin Yu explained here:
http://tinyurl.com/9tw6c
but it doesn't work. :(
I'm using WinXP Pro SP2 and latest IE. I don't have Office 2003 installed.
What should I do?
| |
by: Darryl Kerkeslager |
last post by:
Below is a section of the code I use to open Word with late binding, insert
text at the selected bookmarks, and make Word visible. Everything works
fine. However, I also have some Word check boxes, that I cannot figure out
how to make 'checked'. I am not allowed to alter the layout of the form; it
must be a check box. Up until now, I have simply required users to check
the box themselves, but now I'm opening up four Word forms that all...
|
by: Claus - Arcolutions |
last post by:
I got a word document as a stream, and I want to get the text from the word
document. But I cant seem to find anything to use for that purpose.
The "Microsoft office ?.object" com reference, only include functionality to
read from a file (as far as I know).
I looked a little on the structure of the document, but it doesnt seem to
have any common structures, especially not if you compare from different
office versions.
|
by: Filip De Backer |
last post by:
hi everyone,
I want a textbox with word layout.
And than save this text to a field in a sql server.
how can I do that?
thanks for the answers
Filip
|
by: Shar Shar |
last post by:
Hi All,
Actually I want to use "Word.ApplicationClass" class for opening a word file. And do following things,
1) Open word file.
2) Insert text in bookmark field.
3) Print resultant file as pdf.
Has anyone solution how can I do this programmatically in C#.
|
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...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |