cp's OEIS Frontend

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.

A330674 Lexicographically earliest infinite sequence of distinct nonnegative terms such that a(n+1) is obtained by adding to a(n) the odd digits of a(n) and subtracting the even ones.

Original entry on oeis.org

1, 2, 0, 3, 6, 4, 5, 10, 11, 13, 17, 25, 28, 18, 7, 14, 8, 9, 12, 15, 21, 20, 16, 19, 29, 36, 33, 39, 51, 57, 69, 72, 77, 91, 101, 103, 107, 115, 122, 119, 130, 134, 22, 23, 24, 26, 27, 32, 30, 31, 35, 43, 42, 34, 37, 47, 50, 55, 65, 64, 54, 38, 40, 41, 44, 45, 46, 48, 49, 52, 53, 61, 56, 58, 59, 73, 83, 78
Offset: 1

Views

Author

Eric Angelini and Carole Dubois, Dec 24 2019

Keywords

Comments

When an iteration reproduces a term already in the sequence, we cancel this iteration and restart the sequence from there with the smallest integer not yet present in the sequence.

Examples

			As a(1) = 1, we get a(2) = 2 by adding the odd digit 1 to a(1);
as a(2) = 2, we  get a(3) = 0 by subtracting the even digit 2 from a(2);
as a(3) = 0, we stop to iterate (0 would produce 0, already in the sequence) and restart the sequence with a(4) = 3, the smallest integer not present;
as a(4) = 3, we get a(5) = 6 by adding the odd digit 3 to a(4);
as a(5) = 6, we stop to iterate (6-6 produces 0, already in the sequence) and restart the sequence with a(6) = 4, the smallest integer not present;
as a(6) = 4, we stop to iterate (4-4 produces 0, already in the sequence) and restart the sequence with a(7) = 5, the smallest integer not present;
as a(7) = 5, we get a(8) = 10 by adding the odd digit 5 to a(7);
as a(8) = 10, we get a(9) = 11 by adding the odd digit 1 to a(8);
as a(9) = 11, we get a(10) = 13 by adding the odd digits 1 and 1 to a(9); etc.
		

Crossrefs

Cf. A036301 (Numbers n such that sum of even digits of n equals sum of odd digits of n).

Programs

  • Mathematica
    Nest[Append[#1, If[FreeQ[#1, #2], #2, Block[{k = 3}, While[! FreeQ[#1, k], k++]; k]] & @@ {#1, #1[[-1]] + Total@ Select[#2, OddQ] - Total@ Select[#2, EvenQ]} & @@ {#, IntegerDigits@ #[[-1]]}] &, {1}, 77] (* Michael De Vlieger, Dec 24 2019 *)