i'm programming a project in BASIC. it prompts for a UPC ID, the program spits out the typical length of the given product. there is a fairly lengthy list of products. does anybody know of an efficient method to do this ? (or, in any case, the _most_ efficient method). any input is greatly appreciated
Quote from: mynameistmp on November 16, 2003, 02:32 PM
i'm programming a project in BASIC. it prompts for a UPC ID, the program spits out the typical length of the given product. there is a fairly lengthy list of products. does anybody know of an efficient method to do this ? (or, in any case, the _most_ efficient method). any input is greatly appreciated
Hash table? This solves the time problem, but is a bitch with space. If you're programming for a TI-83+, that could be a potential problem.
well something along the lines of a hash table was what i had in mind, i'm just not sure how to go about doing that. any suggestions ?
In BASIC, I'm not too sure. Can you convert a string to a uniquish number, and store the string in an array at that number?
If so, you need an array of strings that's a prime numbered size, to insert hash it and try to insert; if something that's not the string is there, increment by some value (mod tablesize) and try again, till either you find it's already there or you find an empty spot.
It's not the best way to do it, of course, but it's easy to insert stuff.
Quote from: iago on November 18, 2003, 05:18 PM
In BASIC, I'm not too sure. Can you convert a string to a uniquish number, and store the string in an array at that number?
If so, you need an array of strings that's a prime numbered size, to insert hash it and try to insert; if something that's not the string is there, increment by some value (mod tablesize) and try again, till either you find it's already there or you find an empty spot.
It's not the best way to do it, of course, but it's easy to insert stuff.
I think that you would turn a string to a hash value the same way you would in any other language, e.g. writing a hash function that accesses all the elements and combines them in some manner, such as xoring (at the most basic)?
Quote from: Skywing on November 19, 2003, 07:04 AM
Quote from: iago on November 18, 2003, 05:18 PM
In BASIC, I'm not too sure. Can you convert a string to a uniquish number, and store the string in an array at that number?
If so, you need an array of strings that's a prime numbered size, to insert hash it and try to insert; if something that's not the string is there, increment by some value (mod tablesize) and try again, till either you find it's already there or you find an empty spot.
It's not the best way to do it, of course, but it's easy to insert stuff.
I think that you would turn a string to a hash value the same way you would in any other language, e.g. writing a hash function that accesses all the elements and combines them in some manner, such as xoring (at the most basic)?
You can add them for all I care :)
It's the array of strings that I'd be more worried about not being able to do. I don't know how TI-83's basic works.
First of all, the TI-83 has 10 strings. I don't know about the 83+s. The string handling functions it has are limited, but you could probably make do with them.