Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Any bored Recursive Custom Function gurus out there?

Featured Replies

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?

Why don't you just post the problem, and a sample file with what you have so far.

  • Author

oops, I thought I had posted the file, sorry.

vcheck.zip

Edited by Guest

  • 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.

Could you point us to the source of the algorithm?

  • 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

See how this works - haven't checked it too extensively.

Edited by Guest
removed attachment

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

  • 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!

We have a Topic for posting of Custom Functions Here Too.

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.

  • Author

Thanks, but I prefer to post my functions myself, and I will do so shortly.

Harrumph...

  • 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.

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"?

  • 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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.