Post Reply 
checkdigit calculation for HP-17b
07-28-2015, 10:11 PM
Post: #21
RE: checkdigit calculation for HP-17b
(07-28-2015 06:22 PM)Thomas Klemm Wrote:  This is a step-by-step transformation of your formula to my solution.

Thanks for that explanation, Thomas, it is very good.

The only reason I had that first MOD in my equation (right after CD=) is to take care of the case where the mod of the sum was 0, because when I subtracted that from 10 the result would be checkdigit 10, which is wrong of course. So, that first MOD seemed to be the easiest way to take care of the 0 and not bother the other results 1-9. I could have used an IF I guess, but I wanted to avoid IF's.

What you did would have never occurred to me because I would have wanted to avoid negative numbers, I never considered that using negative numbers could have resulted in an even better example of code, given how MOD uses INT and that treats negative numbers in an advantageous way in this particular application.

I much appreciate your insights.

Don
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: checkdigit calculation for HP-17b - Don Shepherd - 07-28-2015 10:11 PM



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