Implements the Luhn test succinctly.
Python, 3 lines
1 2 3
def luhn(n): r = [int(ch) for ch in str(n)][::-1] return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0
This solution was chosen as I had to factor the convoluted wikipedia description to find a better way to calculate the answer. I prefer this description, posted on Rosetta Code.
Original wikipedia Python code is more readable than this recipe: