Skip to main content
added 1417 characters in body
Source Link
Unrelated String
  • 23k
  • 3
  • 32
  • 55

Jelly, 10 bytes

_ƝµṂƇNṖ⁼ṬƇ

Try it online!

Semi-translation of Leo's excellent Husk answer.

_Ɲ            Take the vectorized differences between adjacent elements.
              (The deltas builtin, I, vectorizes itself instead.)
   ṂƇ         Filter by minimum, keeping elements containing -1.
     N        Negate.
      Ṗ       Remove the last element.
       ⁼      Is this list equal to
  µ           the differences
        ṬƇ    filtered to only elements containing 1?

was originally (maximum), but this produced a false negative on the first test case, as the largest element of [-1] is -1 rather than 0. produces an array with ones at the provided indices and zeros elsewhere, but ignores non-positive indices, producing an empty array (which is falsy) if there are no positive indices.

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest

Takes input as an array of Boolean arrays, and outputs 0 or 1.

   ɗ\            Cumulatively reduce the input by:
ṛ                right argument
 a               vectorizing-logical-AND
  +              the vectorized sum of the arguments.
ṛa+ɗ\            This turns each 1 into how "long" it's been a 1, consecutively.
          ʋƝ     For each pair of adjacent elements from that result:
      T          are the indices at which
     >           the right is less than the left
       ẇ         a sublist of
        M{       the maximal indices of the left?
            P    Take the product of the results.

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest

Takes input as an array of Boolean arrays, and outputs 0 or 1.

   ɗ\            Cumulatively reduce the input by:
ṛ                right argument
 a               vectorizing-logical-AND
  +              the vectorized sum of the arguments.
ṛa+ɗ\            This turns each 1 into how "long" it's been a 1, consecutively.
          ʋƝ     For each pair of adjacent elements from that result:
      T          are the indices at which
     >           the right is less than the left
       ẇ         a sublist of
        M{       the maximal indices of the left?
            P    Take the product of the results.

Jelly, 10 bytes

_ƝµṂƇNṖ⁼ṬƇ

Try it online!

Semi-translation of Leo's excellent Husk answer.

_Ɲ            Take the vectorized differences between adjacent elements.
              (The deltas builtin, I, vectorizes itself instead.)
   ṂƇ         Filter by minimum, keeping elements containing -1.
     N        Negate.
      Ṗ       Remove the last element.
       ⁼      Is this list equal to
  µ           the differences
        ṬƇ    filtered to only elements containing 1?

was originally (maximum), but this produced a false negative on the first test case, as the largest element of [-1] is -1 rather than 0. produces an array with ones at the provided indices and zeros elsewhere, but ignores non-positive indices, producing an empty array (which is falsy) if there are no positive indices.

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest

Takes input as an array of Boolean arrays, and outputs 0 or 1.

   ɗ\            Cumulatively reduce the input by:
ṛ                right argument
 a               vectorizing-logical-AND
  +              the vectorized sum of the arguments.
ṛa+ɗ\            This turns each 1 into how "long" it's been a 1, consecutively.
          ʋƝ     For each pair of adjacent elements from that result:
      T          are the indices at which
     >           the right is less than the left
       ẇ         a sublist of
        M{       the maximal indices of the left?
            P    Take the product of the results.
added 639 characters in body
Source Link
Unrelated String
  • 23k
  • 3
  • 32
  • 55

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest

Takes input as an array of Boolean arrays, and outputs 0 or 1.

   ɗ\            Cumulatively reduce the input by:
ṛ                right argument
 a               vectorizing-logical-AND
  +              the vectorized sum of the arguments.
ṛa+ɗ\            This turns each 1 into how "long" it's been a 1, consecutively.
          ʋƝ     For each pair of adjacent elements from that result:
      T          are the indices at which
     >           the right is less than the left
       ẇ         a sublist of
        M{       the maximal indices of the left?
            P    Take the product of the results.

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest

Takes input as an array of Boolean arrays, and outputs 0 or 1.

   ɗ\            Cumulatively reduce the input by:
ṛ                right argument
 a               vectorizing-logical-AND
  +              the vectorized sum of the arguments.
ṛa+ɗ\            This turns each 1 into how "long" it's been a 1, consecutively.
          ʋƝ     For each pair of adjacent elements from that result:
      T          are the indices at which
     >           the right is less than the left
       ẇ         a sublist of
        M{       the maximal indices of the left?
            P    Take the product of the results.
Source Link
Unrelated String
  • 23k
  • 3
  • 32
  • 55

Jelly, 15 13 bytes

ṛa+ɗ\>TẇM{ʋƝP

Try it online!

-2 removing ṙ1 because the all-zeros pattern can essentially be ignored--if you flip the last bit off, you already know it's the one that's been on the longest