Skip to main content
1 of 2
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
Jo King
  • 47.5k
  • 5
  • 125
  • 186