sum of the first n integers Message #1 Posted by Gerson W. Barbosa on 30 May 2010, 5:28 p.m.
Most everybody here knows the story of young Gauss being asked by his teacher to add together the first 100 natural numbers and how he did it quickly in a very genial way. Lacking his genius, I will do it the old-fashioned way, summing the numbers one by one, not only the first 100 of them, but as much as I can do in 60 seconds using some different programmable calculators:
HP-12C HP-33s HP-34c
01 1 G0001 LBL G 001 LBL A
02 ENTER G0002 1 002 1
03 ENTER G0003 ENTER 003 ENTER
04 1 H0001 LBL H 004 LBL 1
05 + H0002 1 005 1
06 + H0003 + 006 +
07 STO 0 H0004 + 007 +
08 LST x H0005 STO A 008 STO 0
09 GTO 04 H0006 LAST x 009 LST x
H0007 GTO H 010 GTO 1
Execute the program and start your chronometer. When exactly one minute has elapsed, press the R/S key, recall the sum S from the memory register and compute n = (sqrt(8*S + 1) - 1)/2 or INT(e^((ln(S) + ln(8))/2 - ln(2))), in case 8*S might exceed the number of digits in the display.
The following results were obtained:
calculator S n
HP-12c+ 58 001 835 10 770
HP-33s 7 610 851 3 901
HP-12c 14 365 169
HP-34c 6 441 113
These can be used to be benchmark the performance of the calculators. For instance, I gather from the table my HP-12c+ is 63.7 times faster then the ordinary 12c (10770/169) and my 33s is 34.5 times faster than my 34c. The latter agrees with other benchmarks:
Tony Thimet's Benchmark
HP-33s: 44.0
HP-34c: 1.3
-> 33.85x
Xerxes's Benchmark
HP-34c: 4390 s
HP-33s: 131 s (my units)
-> 33.51x
Gene Wright's Benchmark
HP-33s: 9900
HP-34c: 269 (my units)
-> 36.8x
Apart from the benchmarking feature, I am interested in how many counts you can get, either from trying the program in faster calculator or improving the method. For instance, on the HP-41 1 STO and then RCL 1 inside the loop is faster than the 1 in the beginning of the loop (thanks PeterP!).
Gerson.
|