Sign in to follow this  

Determining An Algorithm

This topic is 4307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so usually I'm okay at determining algorithms and this one doesn't seem too complex I just can't get my head around it though. What I have to do is I'm taking a string of a name of a Model. So say the model name is Extra GamingT Pro. Normally by looking at that I would determine a 3 digit code to represent that model in my database. EGP First letter of each word. Now if I just had GamingT Pro the string would be GPR first and second letter of each word. If that was in use it would be GPO and if that was in use then GAP and so on. Until I am able to develop a code that represents that model that has not been used already. Now here is the problem. That is really easy to do manually but I'm having difficulties determine an algorithm to do it. I've got psuedo code written out as to how I can think of doing it but just can't place my words into code.
Quote:
PSUEDO CODE GENERATE NEW ID DETERMINE AMMOUNT OF WORDS USING WORDS DETERMINE DIGITS CHECK IF DUPLICATE ID IF DUPLICATE REPEAT PROCESS WITH NEXT LETTER CONTINUE THROUGH STEPS UNTIL COMPLETE ADD MODEL AND CODE TO TABLES
But placing this to code is difficult, exspecially since I'm using VBA for Excel 2002 which means I'm lacking the complexity that C++ can handle. It is already hard enough to figure out in C++. Anyways any help would be greatly appreciated! Thank you for your time and hope your having a great day. *edit* A better example, I'm drawing some stuff out now :p is this Extreme GamingT So the code would need to grab the E, then it would go to the next word, get the G, then it would realize that hey theres no more words grab second letter of last word so it will get the A. Then does the Compair(EGA) which will return weither or not it already exists. I'm going to say it does exist, so we start the loop over except this time it will be grab the E, then grab the G then get the M. Thats Compair(EGM) and again it exists, next would be EGI though my main still isn't functioning this properly! [Edited by - Surg AKA Kunark on February 28, 2006 10:28:36 AM]

Share this post


Link to post
Share on other sites
I don't know why you'd want a 3-letter code to represent each model. Perhaps because if you include the null char, then it fits in a 32-bit int?

It sounds to me like this is basically just a hash. So why don't you calculate a hash in the normal way, taking every char of the string into account.
You could use every char to generate a 32-bit CRC as the hash for example, which should mean that the chance of a collision is almost zero.

Or, since you appear to just need a unique ID, and it doesn't really have to have anything in common with the original name, then why not just pick the next unused cookie value, which is the max of all previous, plus one.

Share this post


Link to post
Share on other sites
The reason for this is it is apart of a very large SCADA development project. The code has been generated that way manually but it is now being automated. Standards have to be done through out the task. I'm working with Excel, and Oracle Databases as well as a couple other programs that wouldn't be popular enough for you to even consider. These also work inturn with PLC coding.

So standards have to be stuck too, which is why the ID is being generated that way. Which is why I'm still trying to figure it out, I've got some done just gotta fix some things I think. Though I could be wrong.

As for a hash table I don't believe that VBA allows HASH tables. And if it does then I would be much abliged if you could show me an example of how to use one.

Anyways thanks for your reply I'm going to keep working on this until I've completed it. Gotta code it while my mind is in the right place.

Share this post


Link to post
Share on other sites
This sounds like a recursive solution might be in order. Does your language support it?


solve (letters-already-used) (words) (i) (m) =
if count(letters-already-used) == 3 then
if valid(letters-already-used) then
register(letters-already-used)
return SUCCESS
else
return FAILURE
else
// Case 0: no words left!
if count(words) == i return FAILURE

// Case 1: the next letter is not in this word.
// Check the next word.
foreach m <= j < count(words[i]) do
letter = words[i][j]
if solve(letters-already-used + letter) (words) (i+1) (0) == SUCCESS then
return SUCCESS
done

// Case 2: the next letter is in this word.
foreach m <= j < count(words[i]) do
letter = words[i][j]
if solve(letters-already-used + letter) (words) (i) (j+1) == SUCCESS then
return SUCCESS
done

// No other cases: report failure.
return FAILURE

Share this post


Link to post
Share on other sites
Hey! Yea I was thinking Recursive might be needed, though I am not sure if it is supported. I believe it is, as I havn't seen any reason why it may not be. Thanks for the code example, I'm slowly trying to decypher it, I prefer C++ over VB wish I was doing this in C++ :D

What I had I think is almost close to that, though I kind of thought it up jotted down what I had in my head started programming but didn't get everything so I'm missing some parts :p Darn brain doesn't retain information long enough haha.

Again thank you for the help, I'm going to try that out I never knew about the Count() function right now I'm using a Do code WHILE NOT Compair(NOT SAME)

Share this post


Link to post
Share on other sites
Still stumped on this algorithm. Currently my initial plans were to have multiple variables.

Quote:

Dim nDigit As Integer ' This is the digit of the word we are working on
Dim nInitialWordRep As Integer ' This is to determine digit of next from last word
' Have we cleared the entire last word yet?
Dim nInitialWord As Integer ' From where do we start adding InitialWordRep
' How far from last word?
Dim nWordNumber As Integer ' How many words we have
Dim nWord As Integer ' This is the current word we are on
Dim sCode As String ' The produced code!


Not sure if that is explanatory but I was going to loop, and then have one as a digit counter to determine where I am in the word. The other to determine were to start on which word? I'm getting alittle confused with my explanation myself.

Anyways long story short, I realized that there was no way that was going to work. As I never accounted for four words, or more and getting it to do what I thought it was going to do seemed to prove difficult. As for a hash table, I still am unsure on how to do that or even if VBA supports it though I'm betting it does.

Thanks again for all the help!

Share this post


Link to post
Share on other sites

This topic is 4307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this