If the data really is similar in scope to your sample data, you could create a map like this: map = [0 .. 150] for each color: for loc range start * 10 to range finish * 10: map[loc] = color Then just walk through this map to generate the ranges curcolor = none for loc in map: if map[loc] != curcolor: if curcolor: rangeend = loc / 10 make new range rangecolor = map[loc] rangestart = loc / 10 To work, the values have to be in a relatively small range as in your sample data. Edit: to work with true floats, use the map to generate a high level mapping and then refer to the original data to create the boundaries. map = [0 .. 15] for each color: for loc round(range start) to round(range finish): map[loc] = color curcolor = none for loc in map if map[loc] != curcolor: make new range if loc = round(range[map[loc]].start) rangestart = range[map[loc]].start else rangestart = previous rangeend rangecolor = map[loc] if curcolor: if map[loc] == none: last rangeend = range[map[loc]].end else last rangeend = rangestart curcolor = rangecolor