login
List the positive integers but erase commas between terms if the digits just before and just after the comma have the same parity.
2

%I #42 Nov 26 2023 10:55:20

%S 1,2,3,4,5,6,7,8,910,1112,1314,1516,1718,19,2021,2223,2425,2627,

%T 282930,3132,3334,3536,3738,39,4041,4243,4445,4647,484950,5152,5354,

%U 5556,5758,59,6061,6263,6465,6667,686970,7172,7374,7576,7778,79,8081,8283,8485,8687,888990,9192,9394,9596,9798,99100,101102

%N List the positive integers but erase commas between terms if the digits just before and just after the comma have the same parity.

%C Erase a comma if the last digit of previous term and first digit of the following term have the same parity.

%H Michael S. Branicky, <a href="/A365822/b365822.txt">Table of n, a(n) for n = 1..10000</a>

%H Michael De Vlieger, <a href="/A365822/a365822.png">Log log scatterplot of a(n)</a>, n = 1..10^5, showing even terms in red and odd in dark blue.

%e 1112 is in the sequence. We can check by looking at where 11 and 12 appear in the list of natural numbers {..., 10, 11, 12, 13, ...}. The digits that flank the comma in the pair (10,11) are {0,1}, which have opposite parity, so we keep the comma between 10 and 11. This gives {..., <--10, 11-->, ...} [the <-- --> arrows indicate the possibility of more digits to the left and right. Note that 910 is also a member!]. Checking the flanking digits in the pair (11,12), we see that {1,1} have the same parity, so the comma is deleted there to give {..., <--10, 1112-->, ...}. We must keep checking additional pairs to the right until we find a comma. (12,13) has flanking digits {2,1} with opposite parity, so no comma is deleted. Now we see that 1112 is a member, since {..., <--10, 1112, 13-->, ...}.

%t nn = 120; j = {0}; Rest@ Reap[Do[Set[k, IntegerDigits[n]]; If[Mod[Last[j], 2] == Mod[First[k], 2], j = Join[j, k], Sow[FromDigits[j]]; j = k], {n, nn}] ][[-1, 1]] (* _Michael De Vlieger_, Nov 24 2023 *)

%o (Python)

%o from itertools import count, islice

%o def agen():

%o cat = ""

%o for i in count(1):

%o s = str(i)

%o if cat != "" and int(cat[-1])%2 != int(s[0])%2:

%o yield int(cat)

%o cat = ""

%o cat += s

%o print(list(islice(agen(), 55))) # _Michael S. Branicky_, Nov 18 2023

%Y Cf. A000027, A367595 (opposite parity).

%K nonn,base,look

%O 1,2

%A _Wesley Ivan Hurt_, Nov 12 2023