Valhalla Legends Forums Archive | General Programming | TI83+

AuthorMessageTime
mynameistmp
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
November 16, 2003, 8:32 PM
kamakazie
[quote author=mynameistmp link=board=5;threadid=3648;start=0#msg29547 date=1069014739]
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]

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.
November 16, 2003, 9:17 PM
mynameistmp
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 ?
November 18, 2003, 1:25 AM
iago
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.
November 18, 2003, 11:18 PM
Skywing
[quote author=iago link=board=5;threadid=3648;start=0#msg29981 date=1069197483]
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]
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)?
November 19, 2003, 1:04 PM
iago
[quote author=Skywing link=board=5;threadid=3648;start=0#msg30071 date=1069247075]
[quote author=iago link=board=5;threadid=3648;start=0#msg29981 date=1069197483]
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]
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]

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.
November 19, 2003, 2:11 PM
CupHead
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.
November 19, 2003, 5:33 PM

Search