Jelly, (削除) 18 16 (削除ここまで) 1615 bytes
I%5Œg%8’¬S€ṀμÐṀḢI%5Œg%8ċ1ドルṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! Try it online! or see a test suite test suite (with processing to make I/O look like it is in the question).
How?
I%5Œg%8’¬S€ṀμÐṀḢI%5Œg%8ċ1ドルṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a deltadeltas of -9 and -1 with 1 and 9 with -1respectively
Œg - group runs of equal elements
%8 - modulo by 8; vectorised (9s become 1s, others unaffected)
’ - decrement, vectorised
¬ ċ1ドル - not, vectorised (now we havecount groupsnumber of 1s if valid runs or 0s if not)
S€ - sumin €ach group
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, (削除) 18 (削除ここまで) 16 bytes
I%5Œg%8’¬S€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
How?
I%5Œg%8’¬S€ṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a delta of -9 with 1 and 9 with -1
Œg - group runs of equal elements
%8 - modulo by 8; vectorised (9s become 1s, others unaffected)
’ - decrement, vectorised
¬ - not, vectorised (now we have groups of 1s if valid runs or 0s if not)
S€ - sum €ach group
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, (削除) 18 16 (削除ここまで) 15 bytes
I%5Œg%8ċ1ドルṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
How?
I%5Œg%8ċ1ドルṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates deltas of -9 and -1 with 1 and 9 respectively
Œg - group runs of equal elements
%8 - modulo by 8; vectorised (9s become 1s, others unaffected)
ċ1ドル - count number of 1s in €ach group
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, 18(削除) 18 (削除ここまで) 16 bytes
I%5Œgf1,9$€L€ṀμÐṀḢI%5Œg%8’¬S€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! Try it online! or see a test suite test suite (with processing to make I/O look like it is in the question).
How?
I%5Œgf1,9$€L€ṀμÐṀḢI%5Œg%8’¬S€ṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a delta of -9 with 1 and 9 with -1
Œg - group runs of equal elements
%8 $€ - lastmodulo twoby links8; asvectorised a(9s monadbecome for1s, €achothers run:unaffected)
1,9 ’ - one paired with nine -> [1decrement,9]
vectorised
f ¬ - not, vectorised filter(now keepwe (onlyhave runsgroups of 91s orif 1valid willruns nowor have0s anyif elementsnot)
L€S€ - length ofsum €ach valid run (1 less than the actual run, but these are being compared so it has no effect)group
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, 18 bytes
I%5Œgf1,9$€L€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
How?
I%5Œgf1,9$€L€ṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a delta of -9 with 1 and 9 with -1
Œg - group runs of equal elements
$€ - last two links as a monad for €ach run:
1,9 - one paired with nine -> [1,9]
f - filter keep (only runs of 9 or 1 will now have any elements)
L€ - length of €ach valid run (1 less than the actual run, but these are being compared so it has no effect)
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, (削除) 18 (削除ここまで) 16 bytes
I%5Œg%8’¬S€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
How?
I%5Œg%8’¬S€ṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a delta of -9 with 1 and 9 with -1
Œg - group runs of equal elements
%8 - modulo by 8; vectorised (9s become 1s, others unaffected)
’ - decrement, vectorised
¬ - not, vectorised (now we have groups of 1s if valid runs or 0s if not)
S€ - sum €ach group
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, 18 bytes
I%5Œgf1,9$€L€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
How?
I%5Œgf1,9$€L€ṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a delta of -9 with 1 and 9 with -1
Œg - group runs of equal elements
$€ - last two links as a monad for €ach run:
1,9 - one paired with nine -> [1,9]
f - filter keep (only runs of 9 or 1 will now have any elements)
L€ - length of €ach valid run (1 less than the actual run, but these are being compared so it has no effect)
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)
Jelly, 18 bytes
I%5Œgf1,9$€L€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
Jelly, 18 bytes
I%5Œgf1,9$€L€ṀμÐṀḢ
A monadic link taking a list of lists of digits, and returning the leftmost one containing a maximal run as described.
Try it online! or see a test suite (with processing to make I/O look like it is in the question).
How?
I%5Œgf1,9$€L€ṀμÐṀḢ - Link: list of lists of integers (digits) from [0-9]
μÐṀ - keep elements for which the link to the left is maximal:
I - incremental differences (i.e. [a2-a1, a3-a2, ...])
5 - literal 10
% - modulo by (i.e. [(a2-a1)%10, (a3-a2)%10, ...])
- this equates a delta of -9 with 1 and 9 with -1
Œg - group runs of equal elements
$€ - last two links as a monad for €ach run:
1,9 - one paired with nine -> [1,9]
f - filter keep (only runs of 9 or 1 will now have any elements)
L€ - length of €ach valid run (1 less than the actual run, but these are being compared so it has no effect)
Ṁ - maximum
Ḣ - head (get the first one of those that were maximal)