int num = 20; // base number
int i = 0; // index starting at 0, increased to 1 before the first calculation
while (num <= 30000) { // stop the loop if num > 30000
i++; // increase the index
num = num + (20 + i); // 20 + 21 + 22 + ... + n + n+1
}
System.out.println("Number: " + num + " | Index: " + i); // output results
Number: 30191 | Index: 226
"//" denotes comments explaining the purpose of each line
index 226 is necessary because index 225 = 30191 - 226 = 29965 which is obviously < 30000
this however assumes that 20 = sequence(0) as a base start, and sequence(1) is 20 + 21 = 41, which is fairly standard.
but you say: Each sequence is previous +1 (so 20 + (20+1) + (20+2) + (20+3) = 86 for example which was 4 sequences)
if your teacher follows this and teaches you this notion, then you simply add 1 to the result to bring it up to index 227
sequence(1) = 20, sequence(2) = 41, sequence(3) = 63, sequence(4) = 86
when i see this, i assume sequence(0) = 19, thus you are starting at 19 rather than 20.
but if your teacher is teaching you otherwise, you basically just follow their rules or get points deducted even if they are wrong.
if you believe that you may be wrong, and that this rather counts as 3 sequences, then follow with the calculated index 226
sequence(0) = 20, sequence(1) = 41, sequence(2) = 63, sequence(3) = 86
Quote (sentries @ Apr 30 2017 01:54am)
I think your setup might be off. I believe It's 20n + (n-1)(n)/2 = 3000 or alternatively you could add 1 to your solution
his answer matches mine, and we're assuming he followed his formula to achieve his answer.
if you're able to get the same answer using your formula, that only proves that there is more than one formula to solve the same question. which isn't unusual.
This post was edited by Kokua on May 1 2017 08:52am