HP50g small tips and trick
06-23-2018, 05:02 PM
Post: #41
 TomC Member Posts: 102 Joined: Dec 2013
RE: HP50g small tips and trick
Got it - 'N' STO fixed it.

Also, the list is reversed, sol REVLIST at the end of the code is required.

TC
06-23-2018, 05:35 PM
Post: #42
 DavidM Senior Member Posts: 605 Joined: Dec 2013
RE: HP50g small tips and trick
(06-23-2018 05:02 PM)TomC Wrote:  ...Also, the list is reversed, sol REVLIST at the end of the code is required.

For models that don't have REVLIST, you can also add a SWAP before the "+":

Code:
«   → N P   «     {}     WHILE       N     REPEAT       N P MOD SWAP +       N P / FLOOR       'N' STO     END   » »

On the 49G or later RPL systems, the ListExt library has a single command that also does this: I→BL.
06-23-2018, 05:43 PM (This post was last modified: 06-23-2018 05:44 PM by pier4r.)
Post: #43
 pier4r Senior Member Posts: 1,568 Joined: Nov 2014
RE: HP50g small tips and trick
(06-23-2018 04:26 PM)rprosperi Wrote:  When you have no idea at all how long a program may run, it's usually best to include a counter to track the number of iterations and when it exceeds some threshold, exit with a diagnostic message, e.g. "Exceeded 10,000 iterations".

Yes that is true. Though I tend to deviate from theory if the task is not critical. (i.e: I am interested in the results but I can wait)

I learned (also through pain) to do sort of canary deployments (principle that is valid mostly everywhere).
Small tests first. Passed? Good.
Then a bit larger. In the meanwhile I collect timings and I see if the predicted runtimes hold varying the input.
Then I let the program crunch large input values.

In my particular case I could predict the next execution time practically with 100% accuracy (and also the number of loops to execute). Only one loop was related to a random pick that in a very remote case could have ended in "sorry no result is there for what you are searching" and then this would have ended in an infinite loop.

I though "well do I make a fail check condition for this? Nah. It won't happen until the input values are really large. By then I will have fixed it". Instead it happened earlier than expected.

Sometimes I have to be remembered of some programming/planning techniques through slightly bitter experiences, to then be motivated to implement them.

Wikis are great, Contribute :)
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)