A093017 Luhn algorithm double-and-add sum of digits of n.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 7, 8, 9, 10, 11, 12, 13
Offset: 0
Examples
a(18) = 2*1 + 8 = 10. a(59) = (1+0) + 9 = 10 (1 and 0 are the digits in 10 = 2*5).
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- John Kilgo, Using the Luhn Algorithm, DotNetJohn.com.
- Webopedia, Luhn formula
- Wikipedia, Luhn algorithm
- Index entries for sequences related to decimal expansion of n
Programs
-
Haskell
a093017 n = if n == 0 then 0 else a093017 n' + a007953 (2 * t) + d where (n', td) = divMod n 100; (t, d) = divMod td 10 -- Reinhard Zumkeller, Nov 08 2014
-
Python
def a(n): s = str(n) r = s[::-1] x = sum(int(d) for d in r[::2]) x += sum(q if (q:=2*int(d)) < 10 else q-9 for d in r[1::2]) return x print([a(n) for n in range(87)]) # Michael S. Branicky, Jul 23 2024
Formula
a(0)=0; for n not divisible by 10, a(n)=1+a(n-1); for n divisible by 10 but not 50, a(n)=2+a(n-10); for n divisible by 50 but not 100, a(n)=1+a(n-50); for n divisible by 100, a(n)=a(n/100). - Mathew Englander, Aug 04 2021
Comments