Hmm... Here is my guess...
// an example of output
1 3 5 5 2 4 6 6 6 3 3 3 3 4 5 5 1 2 1 2
// then what you need to display is..
1 3 5 5 2 4 6 6 6 [ 3 3 3 3 ] 4 5 5 1 2 1 2
Possible???
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
I agree with coil's approach - just notice that you need to increment counter at the beginning or you'll end up in an infinite loop. Better make it a for loop since you need to count.
java.util.Random rnd = java.util.Random();
for(int i = 0; i < 20; ++i)
{
number = rnd.nextInt(6) + 1;
s += number;
}
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
If the long run is what I guess, you can check for the number while each number is generated. You need 2 arrays size 7 and a variable to keep track of the previous generated number and the starting position. Every time a number is generated, check if the new value is equal to the previous value. If it is, increase the value inside subscribe array by 1. If not, check if the value in the subscribe array which the number belongs to is equal to 0. If it is, increment by 1; otherwise, set it to 1 and set the starting position to the number of number generation so far. At the end of the generation, you already know all the run for each number and position...
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
@coil,
Your code suggestion has multiple issues in searching for long combo. 1)It is ambiguous the way you write it, 2)you declare variables and uses them, but you don't explain where and how to assign value to ALL of them and, 3)the algorithm cannot detect multiple long combos (there are 2 or more number with the same length of combo).
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
@coil,
For 1) I had to reread again to understand that the if statement cover up to its own line. The reason is because there is the word 'then' at the starting of the line next to it. It gives me an impression for if-then which could include both 'then' after the statement.
For 2) You do not reassign cstart anywhere --> would not work unless the cstart is assign to 'i' inside your if statement
For 3) Please look at my example again. How many 3s and 6s in its combo?
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239