# Khan/khan-exercises

### Subversion checkout URL

You can clone with
or
.
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (69 sloc) 3.084 kB
 Integer sums
randRange(1, 100) randRange(2, 6) randRange(1, 2) randRange(1, SEQ_LENGTH) DIFFERENCE * SEQ_LENGTH * (SEQ_LENGTH - 1) / 2 FIRST_NUM * SEQ_LENGTH + C (function() { if (DIFFERENCE === 1) { return "integer"; } else if (isOdd(FIRST_NUM)) { return "odd number"; } else { return "even number"; } })() (function() { var sequence = "x"; for (var i = 1; i < SEQ_LENGTH; i++) { sequence += "+ (x + " + (i * DIFFERENCE) + ")"; } return sequence; })() FIRST_NUM + (TARGET_NUMBER - 1) * DIFFERENCE

The sum of SEQ_LENGTH consecutive SEQ_TYPEs is SUM.

What is the ordinal(TARGET_NUMBER) number in this sequence?

Call the first number in the sequence x.

The next SEQ_TYPE in the sequence is x + DIFFERENCE

The sum of the SEQ_LENGTH consecutive SEQ_TYPEs is:

SEQUENCE = SUM

SEQ_LENGTHx + C= SUM

SEQ_LENGTHx = SUM - C

x = FIRST_NUM

Thus, the first number is ANSWER.

Since x is the first number, x + (TARGET_NUMBER - 1) * DIFFERENCE is the ordinal(TARGET_NUMBER) SEQ_TYPE.

Thus, the ordinal(TARGET_NUMBER) number in the sequence is ANSWER.
Something went wrong with that request. Please try again.