Previous commit had a bug, where if a number appeared twice, it would
print twice, separating ranges. This skips all but the final repetition
of a number to prevent ranges from being split by duplicates.