I’m making a Yahtzee game and I need a way to calculate a small straight (a sequence of 4 numbers in order). So valid ones would be: 1,2,3,4 | 2,3,4,5 | 3,4,5,6.
I have an array of 5 numbers and I need to figure out if one of those 3 combinations is in that array.
For those not familiar with Yahtzee, there are 5 dice (the five numbers in the array) that can be from 1-6.
Not sure about the rules of the game, but that should do it.
The function is going to return the first solution it finds – in this case
[1,2,3,4]. It is going to return the booleanfalseif it doesn’t find any straights in the hand. Hope this helps.