# Khan/khan-exercises

Older
100644 72 lines (69 sloc) 3.01 KB
 5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 1 04c8cdc Use ordinal function petercollingridge authored Feb 19, 2013 2 5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 3 4 5 Integer sums 6 7 8 9
10
11 randRange(1, 100) 323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 12 randRange(2, 6) 5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 13 randRange(1, 2) d430c30 Implemented some suggestions petercollingridge authored Jun 25, 2012 14 randRange(1, SEQ_LENGTH) 323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 15 DIFFERENCE * SEQ_LENGTH * (SEQ_LENGTH - 1) / 2 16 FIRST_NUM * SEQ_LENGTH + C 17 18 (function() { 19 if (DIFFERENCE === 1) { 20 return "integer"; 21 } else if (isOdd(FIRST_NUM)) { 22 return "odd number"; 23 } else { 24 return "even number"; 25 } 26 })() 27 5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 28 29 (function() { 323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 30 var sequence = "x"; 344207c Whitespacing petercollingridge authored Feb 20, 2013 31 for (var i = 1; i < SEQ_LENGTH; i++) { 323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 32 sequence += "+ (x + " + (i * DIFFERENCE) + ")"; 5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 33 } 34 return sequence; 35 })() 36 d430c30 Implemented some suggestions petercollingridge authored Jun 25, 2012 37 FIRST_NUM + (TARGET_NUMBER - 1) * DIFFERENCE 5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 38
39 40
41
323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 42

The sum of SEQ_LENGTH consecutive SEQ_TYPEs is SUM.

04c8cdc Use ordinal function petercollingridge authored Feb 19, 2013 43

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

323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 44

5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 45
46
47 48
e85f8b9 Tweak hints petercollingridge authored Feb 20, 2013 49

Call the first number in the sequence x.

d430c30 Implemented some suggestions petercollingridge authored Jun 25, 2012 50

The next SEQ_TYPE in the sequence is x + DIFFERENCE

5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 51
e85f8b9 Tweak hints petercollingridge authored Feb 20, 2013 52

The sum of the SEQ_LENGTH consecutive SEQ_TYPEs is:

323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 53

SEQUENCE = SUM

5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 54
323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 55

SEQ_LENGTHx + C= SUM

344207c Whitespacing petercollingridge authored Feb 20, 2013 56

SEQ_LENGTHx = SUM - C

323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 57

x = FIRST_NUM

d430c30 Implemented some suggestions petercollingridge authored Jun 25, 2012 58
59

Thus, the first number is ANSWER.

5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 60
323cdd7 Working integer sum exercise petercollingridge authored Jun 24, 2012 61
04c8cdc Use ordinal function petercollingridge authored Feb 19, 2013 62

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

5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 66
e85f8b9 Tweak hints petercollingridge authored Feb 20, 2013 67
Thus, the ordinal(TARGET_NUMBER) number in the sequence is ANSWER.
5055c92 Start integer sum exercise petercollingridge authored Jun 23, 2012 68
69
70 71
Something went wrong with that request. Please try again.