Skip to main content
deleted 8 characters in body
Source Link
theorist
  • 1.5k
  • 5
  • 12

Wolfram Language (Mathematica), 37 36 bytes

Last@*Select[Tr@#==0&]@*Subsequences

-1 byte from att using function composition

Try it online!

Subsequences generates all contiguous subsequences;subsequences, sorted by length; Select[Tr@#==0&] selects those whose trace (total) is 0, and sorts them by length;0; Last selects the last, and thus longest, of these subsequences.

att also shows, in the comments, a different approach from mine that is 35 bytes:

Last@Pick[#,Tr/@#,0]&@*Subsequences

Wolfram Language (Mathematica), 37 36 bytes

Last@*Select[Tr@#==0&]@*Subsequences

-1 byte from att using function composition

Try it online!

Subsequences generates all contiguous subsequences; Select[Tr@#==0&] selects those whose trace (total) is 0, and sorts them by length; Last selects the last, and thus longest, of these subsequences.

att also shows, in the comments, a different approach from mine that is 35 bytes:

Last@Pick[#,Tr/@#,0]&@*Subsequences

Wolfram Language (Mathematica), 37 36 bytes

Last@*Select[Tr@#==0&]@*Subsequences

-1 byte from att using function composition

Try it online!

Subsequences generates all contiguous subsequences, sorted by length; Select[Tr@#==0&] selects those whose trace (total) is 0; Last selects the last, and thus longest, of these subsequences.

att also shows, in the comments, a different approach from mine that is 35 bytes:

Last@Pick[#,Tr/@#,0]&@*Subsequences

added 184 characters in body
Source Link
theorist
  • 1.5k
  • 5
  • 12

Wolfram Language (Mathematica), 3737 36 bytes

Last@Select[Subsequences@#,Tr@#==0&]&Last@*Select[Tr@#==0&]@*Subsequences

-1 byte from att using function composition

Try it online!

Subsequences generates all contiguous subsequences; Select...Tr@#==0&Select[Tr@#==0&] selects those whose trace (total) is 0, and sorts them by length; Last selects the last, and thus longest, of these subsequences.

Try it online! att also shows, in the comments, a different approach from mine that is 35 bytes:

Last@Pick[#,Tr/@#,0]&@*Subsequences

Wolfram Language (Mathematica), 37 bytes

Last@Select[Subsequences@#,Tr@#==0&]&

Subsequences generates all contiguous subsequences; Select...Tr@#==0& selects those whose trace (total) is 0, and sorts them by length; Last selects the last, and thus longest, of these subsequences.

Try it online!

Wolfram Language (Mathematica), 37 36 bytes

Last@*Select[Tr@#==0&]@*Subsequences

-1 byte from att using function composition

Try it online!

Subsequences generates all contiguous subsequences; Select[Tr@#==0&] selects those whose trace (total) is 0, and sorts them by length; Last selects the last, and thus longest, of these subsequences.

att also shows, in the comments, a different approach from mine that is 35 bytes:

Last@Pick[#,Tr/@#,0]&@*Subsequences

deleted 82 characters in body
Source Link
theorist
  • 1.5k
  • 5
  • 12

Wolfram Language (Mathematica)Wolfram Language (Mathematica), 5237 bytes

Last@SortBy[Select[Subsequences@#,Tr@#==0&]Last@Select[Subsequences@#,Length]&Tr@#==0&]&

Subsequences generates all contiguous subsequences; Select...Tr@#==0& selects those whose trace is 0; the remainder of the code (there should be a shorter way to do thistotal) is 0, and sorts the subsequencesthem by length and chooseslength; Last selects the last one, and thus longest, of these subsequences.

Try it online!Try it online!

Wolfram Language (Mathematica), 52 bytes

Last@SortBy[Select[Subsequences@#,Tr@#==0&],Length]&

Subsequences generates all contiguous subsequences; Select...Tr@#==0& selects those whose trace is 0; the remainder of the code (there should be a shorter way to do this) sorts the subsequences by length and chooses the last one.

Try it online!

Wolfram Language (Mathematica), 37 bytes

Last@Select[Subsequences@#,Tr@#==0&]&

Subsequences generates all contiguous subsequences; Select...Tr@#==0& selects those whose trace (total) is 0, and sorts them by length; Last selects the last, and thus longest, of these subsequences.

Try it online!

added 243 characters in body
Source Link
theorist
  • 1.5k
  • 5
  • 12
Loading
Source Link
theorist
  • 1.5k
  • 5
  • 12
Loading