This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A343462 #33 Feb 16 2025 08:34:02 %S A343462 9,81,525,3105,18939,114381,693129,4195557,25405586,153820395, %T A343462 931359050,5639156409,34143908573,206733865761,1251728824798, %U A343462 7578945799704,45888871327435,277847147039527,1682304127857000,10185986079451152,61673933253012813,373422269794761171,2260990733622821388 %N A343462 Number of n-digit positive integers that undulate. %C A343462 This is also the number of (2*n-1)-digit palindromes that undulate. %C A343462 Classifying undulating numbers with n digits in initial digits and sign of first digit - second digit eases computation. %H A343462 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/UndulatingNumber.html">Undulating Number</a>. %H A343462 <a href="/index/Rec#order_09">Index entries for linear recurrences with constant coefficients</a>, signature (5,10,-20,-15,21,7,-8,-1,1). %F A343462 a(n) = 45*a(n-2) - 330*a(n-4) + 924*a(n-6) - 1287*a(n-8) + 1001*a(n-10) - 455*a(n-12) + 120*a(n-14) - 17*a(n-16) + a(n-18) for n >= 20. - _Michael S. Branicky_, Apr 17 2021 %F A343462 From _Chai Wah Wu_, Apr 24 2021: (Start) %F A343462 a(n) = 5*a(n-1) + 10*a(n-2) - 20*a(n-3) - 15*a(n-4) + 21*a(n-5) + 7*a(n-6) - 8*a(n-7) - a(n-8) + a(n-9) for n > 10. %F A343462 G.f.: x*(-8*x^9 + 7*x^8 + 63*x^7 - 45*x^6 - 162*x^5 + 81*x^4 + 150*x^3 - 30*x^2 - 36*x - 9)/(x^9 - x^8 - 8*x^7 + 7*x^6 + 21*x^5 - 15*x^4 - 20*x^3 + 10*x^2 + 5*x - 1). (End) %e A343462 a(2) = 81 as there are 90 2-digit positive integers (10, 11, ..., 99). Of those, 11, 22, ..., 99 do not undulate as there is a pair of consecutive digits that are equal. There are nine nonundulating 2-digit numbers, leaving 90-9 = 81 that do undulate. %e A343462 134 does not undulate as there are two pairs of consecutive digits where the right one is in both cases either smaller or larger. (In this case 1 < 3 and 3 < 4.) %e A343462 143 does undulate since 1 < 4 and 4 > 3. %o A343462 (PARI) first(n) = { my(res = vector(n), vup, vdown, nvup, nvdown); res[1] = 9; vup = vector(9, i, 1); vdown = vector(9, i, 1); for(i = 2, n, nvup = vector(9); nvdown = vector(9); nvdown[1] = vdown[9]; for(i = 2, 9, nvdown[i] = nvdown[i-1]+vup[i-1] ); for(i = 1, 8, nvup[i] = nvdown[9-i] ); vup = nvup; vdown = nvdown; res[i] = vecsum(vup)+vecsum(vdown)); res } %o A343462 (Python) %o A343462 def aupton(terms): %o A343462 up, dn, alst = [0] + [1]*9, [0] + [1]*9, [9] %o A343462 for n in range(2, terms+1): %o A343462 up_next = [sum(dn[j] for j in range(i)) for i in range(10)] %o A343462 dn_next = [sum(up[j] for j in range(i+1, 10)) for i in range(10)] %o A343462 up, dn = up_next, dn_next %o A343462 alst.append(sum(up + dn)) %o A343462 return alst %o A343462 print(aupton(22)) # _Michael S. Branicky_, Apr 16 2021 %o A343462 (Python) # alternate program as a linear system %o A343462 import numpy as np %o A343462 from sympy import Matrix %o A343462 def aupton(terms): %o A343462 x = Matrix([0] + [1]*9 + [0] + [1]*9) %o A343462 c = Matrix([[1]*20]) %o A343462 z10 = np.zeros((10, 10), dtype=np.int64) %o A343462 o10 = np.ones((10, 10), dtype=np.int64) %o A343462 A = Matrix(np.block([[z10, np.tril(o10, -1)], [np.triu(o10, +1), z10]])) %o A343462 alst = [9] %o A343462 for n in range(2, terms+1): %o A343462 x = A*x %o A343462 alst.append((c*x)[0]) %o A343462 return alst %o A343462 print(aupton(22)) # _Michael S. Branicky_, Apr 16 2021 %Y A343462 Cf. A057332. Apart from the first 2 terms, the same as A152464. %K A343462 nonn,easy,base %O A343462 1,1 %A A343462 _David A. Corneth_, Apr 16 2021