An attempt at the Luhn algorithm in XQuery
✓ Published0🌍 Public
CCliffordAnderson
Last edited Dec 1, 2016
Created on Jun 27, 2013
This example demonstrates the Luhn algorithm, a checksum formula used to validate identification numbers, implemented in XQuery. It checks a sequence of sample numbers from Wikipedia, returning a boolean value indicating whether each number passes validation. The code uses the XQuery 3.1 `fn:fold-left` and `fn:sum` higher-order functions to compute digit sums, and the `fn:reverse` function to process digits from right to left. It includes a recursive `local:number-to-seq` function to convert an integer into a sequence of its digits. The source is a gist by CliffordAnderson, provided in two versions: a standalone script and a library module.
AI-generated description