Skip to main content
edited body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94

J, 40 29 19 18 15 14 1413 bytes

|.~1+0{[:\&\:+/\

Try it online!Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by...
  • 1+ 1 plus...
  • 0{ the first element of...
  • \: the grade down of...
  • +/\ the scan sum.

That is, take the index of the max element of the scan sum, add one to it, and rotate by that amount.

J, 40 29 19 18 15 14 bytes

|.~1+0{[:\:+/\

Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by...
  • 1+ 1 plus...
  • 0{ the first element of...
  • \: the grade down of...
  • +/\ the scan sum.

That is, take the index of the max element of the scan sum, add one to it, and rotate by that amount.

J, 40 29 19 18 15 14 13 bytes

|.~1+0{&\:+/\

Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by...
  • 1+ 1 plus...
  • 0{ the first element of...
  • \: the grade down of...
  • +/\ the scan sum.

That is, take the index of the max element of the scan sum, add one to it, and rotate by that amount.

deleted 80 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94

J, 40 29 19 18 15 1514 bytes

(|.~1 e.~1+0{[:\:+/\)^:_

Try it online!Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by the following amount...
  • 1 e.+/\1+ is 1 anplus...
  • 0{ the first element of the scan sum? Returns 1 or 0...
  • ^\:_ until a fixed point is reachedthe grade down of...
  • +/\ the scan sum.

When 1That is no longer an, take the index of the max element of the scan sum, we'lladd one to it, and rotate by 0 -- that is, stay the same. So the fixed point is reached exactly when we hit the first solutionamount.

J, 40 29 19 18 15 bytes

(|.~1 e.+/\)^:_

Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by the following amount
  • 1 e.+/\ is 1 an element of the scan sum? Returns 1 or 0.
  • ^:_ until a fixed point is reached.

When 1 is no longer an element of the scan sum, we'll rotate by 0 -- that is, stay the same. So the fixed point is reached exactly when we hit the first solution.

J, 40 29 19 18 15 14 bytes

|.~1+0{[:\:+/\

Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by...
  • 1+ 1 plus...
  • 0{ the first element of...
  • \: the grade down of...
  • +/\ the scan sum.

That is, take the index of the max element of the scan sum, add one to it, and rotate by that amount.

added 200 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94

J, 40 29 19 18 1815 bytes

1&|.^:(1|.~1 e.+/\)^:_

Try it online!Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

After that, it's an almost literal translation based on one of Leo's comments:

how

  • 1&||.~ Rotate left...
  • ^:(...)^:_ while...by the following amount
  • 1 e.+/\ 1 is 1 an element of the scan sum? Returns 1 or 0.
  • ^:_ until a fixed point is reached.

When 1 is no longer an element of the scan sum, we'll rotate by 0 -- that is, stay the same. So the fixed point is reached exactly when we hit the first solution.

J, 40 29 19 18 bytes

1&|.^:(1 e.+/\)^:_

Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

After that, it's an almost literal translation based on one of Leo's comments:

  • 1&|. Rotate left...
  • ^:(...)^:_ while...
  • 1 e.+/\ 1 is an element of the scan sum.

J, 40 29 19 18 15 bytes

(|.~1 e.+/\)^:_

Try it online!

-11 after applying HyperNeutrino's scan sum idea

-10 after reading Leo's comment to HyperNeutrino: while(any of the cumulative sum is negative)(rotate by 1)

-3 thanks to a clever observation by Bubbler

Takes input as a list of integers, where [ = _1 and ] = 1 -- reversing the more natural order saves 1 byte.

how

  • |.~ Rotate by the following amount
  • 1 e.+/\ is 1 an element of the scan sum? Returns 1 or 0.
  • ^:_ until a fixed point is reached.

When 1 is no longer an element of the scan sum, we'll rotate by 0 -- that is, stay the same. So the fixed point is reached exactly when we hit the first solution.

added 105 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading
added 105 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading
added 70 characters in body
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading
Source Link
Jonah
  • 33.8k
  • 4
  • 40
  • 94
Loading