Simple challenge: given a series of positive integer numbers, find the number that contains among its digits the longest run of consecutive digits. The trick? It's allowed for the digits in the runs to wrap around the possible values (0123456789
) and to run backwards. So both 2345
, 89012
and 5432109
are valid runs of consecutive digits (but not 3456765
nor 321090123
as the run must be always in the same direction, although 3456765
can be considered as two runs: 34567
and 765
). In the case of ties, return the first one.
Test cases:
Input: [3274569283, 387652323, 23987654323648, 2345687913624]
Output: 23987654323648
(The run is 98765432; run length: 8)
Input: [123012363672023, 098761766325432, 15890123456765]
Output: 15890123456765
(The run is 8901234567; run length: 10)
Input: [43, 19, 456]
Output: 456
Input: [5, 9, 0]
Output: 5
Input: [71232107, 7012347]
Output: 7012347
Input: [1234, 32109876]
Output: 32109876
Input: [9090, 123]
Output: 123
Notes:
- There will be at least one number in the input.
- Input numbers can contain leading zeroes.
- Input and output can be in any reasonable format. So input numbers can be taken as strings, lists of digits/characters...
- Output can contain trailing and/or leading whitespaces and newlines as long as the number is printed.
- This is code-golf, so may the shortest program/function for each language win!
[7,8,1,6]
has a maximal run of[7,8]
rather than[6,7,8]
, yes? \$\endgroup\$78
in that case. \$\endgroup\$