# Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
78 lines (75 sloc) 3.49 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 new Plural(function(num) { return i18n.ngettext("integer", "integers", num); }); } else if (isOdd(FIRST_NUM)) { return new Plural(function(num) { return i18n.ngettext("odd number", "odd numbers", num); }); } else { return new Plural(function(num) { return i18n.ngettext("even number", "even numbers", num); }); } })() (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 plural_form(SEQ_TYPE, SEQ_LENGTH) is SUM.

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

ANSWER

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 plural_form(SEQ_TYPE, SEQ_LENGTH) 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 ordinalThrough20(TARGET_NUMBER) SEQ_TYPE.

Thus, the ordinalThrough20(TARGET_NUMBER) number in the sequence is ANSWER.