Skip to main content
deleted 5 characters in body
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213

Pyth, 9 bytes

ehc2osNyQ

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[1, 2, 4]

Demonstration.Demonstration.

ehc2osNyQ
             Q = eval(input())
       yQ    Take all subsets of Q.
    osN      Order those element lists by their sums.
  c2         Cut the list in half.
eh           Take the last element of the first half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split. We extract the first of those two elements and print it.

Pyth, 9 bytes

ehc2osNyQ

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[1, 2, 4]

Demonstration.

ehc2osNyQ
             Q = eval(input())
       yQ    Take all subsets of Q.
    osN      Order those element lists by their sums.
  c2         Cut the list in half.
eh           Take the last element of the first half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split. We extract the first of those two elements and print it.

Pyth, 9 bytes

ehc2osNyQ

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[1, 2, 4]

Demonstration.

ehc2osNyQ
             Q = eval(input())
       yQ    Take all subsets of Q.
    osN      Order those element lists by their sums.
  c2         Cut the list in half.
eh           Take the last element of the first half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split. We extract the first of those two elements and print it.

deleted 358 characters in body
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213

Pyth, 15 13 129 bytes

@Vc2osNyQtM2ehc2osNyQ

1 byte thanks to Jakube

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[[1[1, 2, 4], [3, 5]]

Demonstration.

@Vc2osNyQtM2ehc2osNyQ
                Q = eval(input())
       yQ       Take all subsets of Q.
    osN         Order those element lists by their sums.
  c2            Cut the list in half.
         tM2    The list [-1, 0]
@V              Vectorize "@", the lookup function, over these two lists.
      eh          This returnsTake the last element of the first half and
                the first element of the second half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split.


If it's only necessary to output We extract the bags carried in onefirst of thethose two hands, the following code is sufficient:elements and print it.

Pyth, 9 bytes

hec2osNyQ

Pyth, 15 13 12

@Vc2osNyQtM2

1 byte thanks to Jakube

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[[1, 2, 4], [3, 5]]

Demonstration.

@Vc2osNyQtM2
                Q = eval(input())
       yQ       Take all subsets of Q.
    osN         Order those element lists by their sums.
  c2            Cut the list in half.
         tM2    The list [-1, 0]
@V              Vectorize "@", the lookup function, over these two lists.
                This returns the last element of the first half and
                the first element of the second half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split.


If it's only necessary to output the bags carried in one of the two hands, the following code is sufficient:

Pyth, 9 bytes

hec2osNyQ

Pyth, 9 bytes

ehc2osNyQ

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[1, 2, 4]

Demonstration.

ehc2osNyQ
             Q = eval(input())
       yQ    Take all subsets of Q.
    osN      Order those element lists by their sums.
  c2         Cut the list in half.
eh           Take the last element of the first half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split. We extract the first of those two elements and print it.

added 109 characters in body
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213

Pyth, 15 1313 12

heJc2osNyQehJ@Vc2osNyQtM2

1 byte thanks to Jakube

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[3, 5]
[1[[1, 2, 4], [3, 5]]

Demonstration.Demonstration.

heJc2osNyQehJ@Vc2osNyQtM2
                 Q = eval(input())
        yQ       Take all subsets of Q.
     osN         Order those element lists by their sums.
   c2            Cut the list in half.
  J       tM2    The list [-1, Save0]
@V it to J           Vectorize "@", the lookup function, over these two lists.
he               Print This returns the firstlast element of the secondfirst half. and
          ehJ    Print  the lastfirst element of the firstsecond half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split.


If it's only necessary to output the bags carried in one of the two hands, the following code is sufficient:

Pyth, 9 bytes

hec2osNyQ

Pyth, 15 13

heJc2osNyQehJ

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[3, 5]
[1, 2, 4]

Demonstration.

heJc2osNyQehJ
                 Q = eval(input())
        yQ       Take all subsets of Q.
     osN         Order those element lists by their sums.
   c2            Cut the list in half.
  J              Save it to J.
he               Print the first element of the second half.
          ehJ    Print the last element of the first half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split.


If it's only necessary to output the bags carried in one of the two hands, the following code is sufficient:

Pyth, 9 bytes

hec2osNyQ

Pyth, 15 13 12

@Vc2osNyQtM2

1 byte thanks to Jakube

Input, output formats:

Input:
[1, 2, 3, 4, 5]
Output:
[[1, 2, 4], [3, 5]]

Demonstration.

@Vc2osNyQtM2
                Q = eval(input())
       yQ       Take all subsets of Q.
    osN         Order those element lists by their sums.
  c2            Cut the list in half.
         tM2    The list [-1, 0]
@V              Vectorize "@", the lookup function, over these two lists.
                This returns the last element of the first half and
                the first element of the second half.

This works because y returns the subsets in such an order that each subset and its complement are equidistant fom the center. Since the sum of a subset and the sum of its complement will always be equidistant from the center, the list after osNyQ will also have this property. Thus, the center two elements of osNyQ are complements, and must have an optimal split.


If it's only necessary to output the bags carried in one of the two hands, the following code is sufficient:

Pyth, 9 bytes

hec2osNyQ
added 21 characters in body
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213
Loading
deleted 567 characters in body
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213
Loading
deleted 567 characters in body
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213
Loading
Source Link
isaacg
  • 42.1k
  • 5
  • 73
  • 213
Loading