Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 10 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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)
deleted 76 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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)
deleted 65 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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)
deleted 65 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
Post Undeleted by Jonathan Allan
deleted 65 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
Post Deleted by Jonathan Allan
Post Undeleted by Jonathan Allan
deleted 323 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
added 71 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
Post Deleted by Jonathan Allan
edited body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
added 107 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading

AltStyle によって変換されたページ (->オリジナル) /