Each of these values seems to be in the format of letter followed by 4 numbers.
Options could be
1 - treat them as strings, and just use
string comparisions. Should work as long as all of the values are in this defined format.
2 - encode it as an object with "letter" and "number" attributes, and write an appropriate comparator.
In terms of general algorithm you could follow a few approaches
Simple stupid algorithm:
For each code you want to look up:
for each sample
for each range in the sample
check if the code falls in the range of that sample.
Each time you lookup a code you have to search through each sample, and all its ranges.
A smarter way might be to build a map of code ranges to samples
So that you in effect have the data in a structure like this:
A4206-A9999 : Sample1
B4000-B9999 : Sample1, Sample2
G0008-G9156: Sample3
...
Given this structure, it becomes more efficient to discover which sample (if any) a code is in.
It would be
- find the code (could do a binary search rather than looking through each entry)
- if it has an entry in this table, then you have your answer
- the problem becomes building and maintaining this table :-)