Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Mathematician David Galeproposed the concept of a \"perfect median\" of a sequen

ID: 3616560 • Letter: M

Question

Mathematician David Galeproposed the concept of a "perfect median" of a sequence.
(American Scientist, Sept.-Oct. 2008) The sequence 1, 2, 3, 4, 5,6, 7, 8 has a perfect median,
namely 6, because the sum of the terms preceding 6 is equal to thesum of the terms following 6.

Note that for this problem the sequence always starts at 1.

Our goal is to find all perfect medians less than 10,000 by writinga program written in MIPS
assembly language and running on SPIM. I recommend doing a littlemathematical analysis of the problem before writing your code. Youmight reduce the run time significantly. Mathematician David Galeproposed the concept of a "perfect median" of a sequence.
(American Scientist, Sept.-Oct. 2008) The sequence 1, 2, 3, 4, 5,6, 7, 8 has a perfect median,
namely 6, because the sum of the terms preceding 6 is equal to thesum of the terms following 6.

Note that for this problem the sequence always starts at 1.

Our goal is to find all perfect medians less than 10,000 by writinga program written in MIPS
assembly language and running on SPIM. I recommend doing a littlemathematical analysis of the problem before writing your code. Youmight reduce the run time significantly.

Explanation / Answer

The math behind this is based on triangle numbers,namely: 1 1+2 = 3 1+2+3 = 6 1+2+3+4+5 = 10 etc.. You can generate the nth triangle number t simply asfollows: (n(n+1))/2 = t_n Hence you can restrict your search to examine only thetriangle numbers less than 10,000 -- there are 140 of them. Atriangle number is so named because, if you were to form a triangleof dots then the triangle number would be the number of dots in thetriangle, like this: . = 1 . .. = 3 . .. ... = 6 . .. ... .... = 10 There is an easy check that you can perform on each of yourtriangle numbers to determine if it is the sum of a "perfectmedian" sequence. As a hint, what do you get (geometricallyspeaking) when you add two right-triangles together?