I'm trying to optimize the performance of a particular program, and I think the solution might exist in the form of a mathematic formula that I'm trying to identify.
Description of the problem:
I've built a program that can take a RummiKub hand of tiles (each tile being comprised of a color and a number). One of the constraints of a valid solution is that every Run that can be made with the hand of tiles must be comprised of tiles whose numbers can be arranged into consecutive order.
Current (functional) solution:
I determine whether this constraint is met by sorting the list of tile numbers in descending order, and checking to see that as I go down the list, each number is exactly one less than the one preceding it.
Better solution I'm looking for:
My current solution has an (admittedly negligible) impact on performance.
I'm attempting to check this constraint by finding some unique relationship between the sum of a set of integers and the number of integers in the set. That way I can keep a running sum of the tile numbers, and when it comes time to check it's validity I can apply this relationship property to the sum and the number of tiles and determine if the list is made of consecutive integers.
Is there such a relationship that I can use for this purpose?