Skip to main content
-1 byte
Source Link
Jo King
  • 47.5k
  • 5
  • 125
  • 186

Perl 6, 5050 49 bytes

{max map *>>*.&map({.[$++;$^b][$++]}).sum,permutations ^.[0][Z] $_}

Try it online!Try it online!

Decently short, even despite the long permutations call. This is an anonymous code block that takes a list of lists and returns a number.

Explanation:

{                                                }   # Anonymous code block that
 max                                                 # Finds the maximum
                               permutations            # Of all permutations
                                            ^.[0]   [Z] $_  # Of the range 0 totransposed n-1input
     map                                               # When mapped to
                          .sum # The sum of
         *>>*.&map({          .[$++]}  )     # For eachThe elementdiagonal of the permutations
               .[$++;$^b]        # That index in each successive list in the inputmatrix

Perl 6, 50 bytes

{max map *>>.&{.[$++;$^b]}.sum,permutations ^.[0]}

Try it online!

Decently short, even despite the long permutations call. This is an anonymous code block that takes a list of lists and returns a number.

Explanation:

{                                                }   # Anonymous code block that
 max                                                 # Finds the maximum
                               permutations            # Of all permutations
                                            ^.[0]      # Of the range 0 to n-1
     map                                               # When mapped to
                          .sum # The sum of
         *>>.&{          }       # For each element of the permutations
               .[$++;$^b]        # That index in each successive list in the input

Perl 6, 50 49 bytes

{max map *.map({.[$++]}).sum,permutations [Z] $_}

Try it online!

Decently short, even despite the long permutations call. This is an anonymous code block that takes a list of lists and returns a number.

Explanation:

{                                               } # Anonymous code block
 max                                              # Finds the maximum
                             permutations         # Of all permutations
                                          [Z] $_  # Of the transposed input
     map                                          # When mapped to
                        .sum # The sum of
         *.map({.[$++]})     # The diagonal of the matrix
Source Link
Jo King
  • 47.5k
  • 5
  • 125
  • 186

Perl 6, 50 bytes

{max map *>>.&{.[$++;$^b]}.sum,permutations ^.[0]}

Try it online!

Decently short, even despite the long permutations call. This is an anonymous code block that takes a list of lists and returns a number.

Explanation:

{                                                }   # Anonymous code block that
 max                                                 # Finds the maximum
                               permutations            # Of all permutations
                                            ^.[0]      # Of the range 0 to n-1
     map                                               # When mapped to
                          .sum # The sum of
         *>>.&{          }       # For each element of the permutations
               .[$++;$^b]        # That index in each successive list in the input