var number1:int=6;
var number2:int=10;
var number3:int=9;
var number4:int=7;
var number5:int=12;
var number6:int=8;
var number7:int=5;
In this code we see that their are 7 integer variables and 5 of them can be made into running consecutive numbers meaning number7=5/nummber1=6/number4= 7/ number6= 8/number3= 9/ number2= 10. My question is how can I determine by code if(5)of thee numbers are running ie 5/6/7/8/9/10.
What if these integer variables were randomly set at the start of the game from 1 to 10 in value. What code is needed to check if at least 5 of them can be made to be running numbers?
There’s no “short-cut” way to do this that I can think of - you’ll simply have to write code that approaches the problem in exactly the same way as you would do manually. That is:
1.) Put all the (n) values into an array
2.) Sort the array into ascending order
3.) Start with the lowest value (n0), and see whether the next highest value is one greater (that is, does n1 = n0 + 1 ?)
4.) If so, increment a counter (i) to keep track of how long the current consecutive run is (2).
5.) Then, consider the next value in the array. Does n2 = n1 + 1?
6.) Each time the next value is equal to the last + 1, increment the counter. Each time it is not, reset the counter. Continue to iterate through all the values in the array in a loop and, at the end, the counter will tell you the greatest consecutive run that has been made.