December 19, 200619 yr I'm trying to create a recursive custom function that will compute a special type of checksum digit. I have a wrapper function that does some initial setup, and some sub-functions that are basically lookup tables, which are used in computing the checksum. All that stuff works fine. I've go a working script that uses a loop to generate the checksum, and that is also working correctly. But I'm trying to move from a script to a recursive custom function, and I suck at thinking recursively. Anyone willing to give me a hand?
December 19, 200619 yr Why don't you just post the problem, and a sample file with what you have so far.
December 19, 200619 yr Author oops, I thought I had posted the file, sorry. vcheck.zip Edited December 19, 200619 yr by Guest
December 20, 200619 yr Author A bit more information... I've done some testing of my script against some presumably reliable sources, such as the CPAN implementation in Perl, and some reference tables, and the results look good. The vCalcsum function I created in an attempt to reproduce this result is obviously broken, I just threw it together to have something in place I could experiment with. The Verify function is pretty much the same thing as the generating function, except it includes the check digit, and if the end result is 0, it's a valid check digit, otherwise it's not. The nice thing about this algorithm compared to others, like Luhn, etc., is that it will detect a single wrong digit, or any single transposed pair of digits, 100% of the time. It also detects a big percentage of other common errors, like if you enter 323 instead of 232, for example, and detects many phonetic errors, like if you say ninety, but someone hears it as nineteen.
December 20, 200619 yr Author Could you point us to the source of the algorithm? Sure thing... It's called the Verhoeff algorithm, and there are several good descriptions of it available online. I started with the wikipedia entry, and then followed some of the links at the bottom of that page for source code and implementation examples. http://en.wikipedia.org/wiki/Verhoeff_algorithm
December 20, 200619 yr See how this works - haven't checked it too extensively. Edited December 20, 200619 yr by Guest removed attachment
December 20, 200619 yr I have taken another look at this and noticed a problem: the input must be treated as text string instead of number, or the function will fail when the string has leading zeros. Also, one function can accomodate both generating the check digit and verifying it. Here's the new file - I *think* it works correctly, but it is really hard to come up with a good testing method for this. Verhoeff.fp7.zip
December 21, 200619 yr Author This is terrific, thanks! I'm planning to post this on Brian Dunning's site, with your permission. Also, one function can accomodate both generating the check digit and verifying it. True, that's one of the nice things about the algorithm, as long as the checksum is appended to the end of the number. Here's the new file - I *think* it works correctly, but it is really hard to come up with a good testing method for this. I'm testing by comparing to thousands of checksums generated using a known-good implementation, and it's looking good so far!
December 21, 200619 yr I'm planning to post this on Brian Dunning's site, with your permission. Thanks, but I prefer to post my functions myself, and I will do so shortly.
December 21, 200619 yr Author Thanks, but I prefer to post my functions myself, and I will do so shortly. Harrumph...
December 21, 200619 yr Author Well, I just ran "your" function through about half a million iterations, comparing it to a known reference file, and it appears to be working perfectly. Congratulations.
December 21, 200619 yr Well, I haven't been able to come up with a test algorithm, so I guess that will have to do. Why do you put quotes around "your"?
December 22, 200619 yr Author Well, I haven't been able to come up with a test algorithm, so I guess that will have to do. I don't think there's much else to be done, unless you got into heavy math. As I understand it, the sequence of permutations is really arbitrarily chosen for its ability to detect typos, and you could replace it with a different P table and it would still generate a checksum, but just not detect the same sorts of errors.
Create an account or sign in to comment