login
Numbers such that |first digit - second digit + third digit - fourth digit ...| = 1.
28

%I #20 Jan 26 2023 16:14:18

%S 1,10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98,100,111,120,122,

%T 131,133,142,144,153,155,164,166,175,177,186,188,197,199,210,221,230,

%U 232,241,243,252,254,263,265,274,276,285,287,296,298,320,331,340,342

%N Numbers such that |first digit - second digit + third digit - fourth digit ...| = 1.

%C Multiples of 11 plus or minus 1. If 11k+1 is a perfect square (see A219257) then a(n) is the square root of 11k+1. [_Gary Detlefs_, Feb 22 2010]

%H Charles R Greathouse IV, <a href="/A061870/b061870.txt">Table of n, a(n) for n = 1..10000</a>

%e 120 is in the sequence since |1-2+0| = 1.

%t fQ[n_] := Abs[Plus @@ (((-1)^Range[Floor[Log[10, n] + 1]])*IntegerDigits@n)] == 1; Select[ Range@342, fQ@# &]

%o (PARI) altsum(v)=sum(i=1,#v,v[i]*(-1)^i)

%o is(n)=abs(altsum(digits(n)))==1 \\ _Charles R Greathouse IV_, May 21 2014

%o (Python)

%o def ok(n): return abs(sum(int(di)*(-1)**i for i, di in enumerate(str(n)))) == 1

%o print([k for k in range(343) if ok(k)]) # _Michael S. Branicky_, Jan 26 2023

%Y Cf. A008593, A060978-A060980, A060982, A061470-A061479, A061870-A061882.

%Y Subsequence of A175885.

%K nonn,base,easy

%O 1,2

%A _Robert G. Wilson v_, May 10 2001