You will check the rearrangement inequality by computer: the sorted pairings against every possible pairing.
The idea. Sorting both lists the same way gives the largest sum of products, and sorting them in opposite ways gives the smallest. The module itertools can list every order of a list with permutations.
Your tasks.
same_order(a, b). Sort both lists in increasing order and return the sum of products.opposite_order(a, b). Sort a increasing and b decreasing.all_totals(a, b). Return a list with the sum of products for every order of b, with a as it is.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…