Posts: 320
Threads: 59
Joined: Dec 2006
I'm not the most efficient programmer in the box. I've written a little program to calculate the partial sums of the function stored in F, iterated as K goes from A to B. Is this about as efficient (minimal steps) the program can get?
Partial Sums
F001 LBL F
F002 1 ÷ K^2
F003 RTN
A001 LBL A
A002 0
A003 STO S
A004 INPUT A
A005 INPUT B
A006 1000
A007 ÷
A008 STO+ A
A009 RCL A
A010 INTG
A011 STO K
A012 XEQ F001
A013 STO+ S
A014 ISG A
A015 GTO A009
A016 VIEW S
A017 RTN
Thanks for any suggestions,
CHUCK
Posts: 3,283
Threads: 104
Joined: Jul 2005
Hi Chuck,
nobody is willing to comment on this? Let me try!
It looks like your loop is perfectly ok. You can save some steps if you redefine F to use the stack instead of K:
F001 LBL F
F002 X^2 ' RPN instead of an equation
F003 1/X
F003 RTN
A001 LBL A
A002 0
A003 STO S
A004 INPUT A
A005 INPUT B
A006 1E3 ' shorter than 1000 (may use the same memory, though)
A007 ÷
A008 STO+ A
A009 RCL A
A010 INTG ' value on stack, not in register
A011 XEQ F002 ' no need to execute the label
A012 STO+ S
A013 ISG A
A014 GTO A009
A015 VIEW S
A016 RTN
I replaced 1000 by 1E3 which might save a byte but need not (I didn't check it).
Marcus