In this challenge, you have to permutate an expression that includes three variable values a, b and c. You are given a set of three unique numbers to substitute for letters so there are six possible different expression variations, and you have to find which one returns the greater result.
expr = "(a - b) * c" | nums = [1, 2, 3]
Permutation #1 ➞ (1 - 2) * 3 = -3
Permutation #2 ➞ (1 - 3) * 2 = -4
Permutation #3 ➞ (2 - 1) * 3 = 3
Permutation #4 ➞ (2 - 3) * 1 = -1
Permutation #5 ➞ (3 - 1) * 2 = 4
Permutation #6 ➞ (3 - 2) * 1 = 1
// Permutation #5 returns the greater result.
Given an expression string expr and an array of three numbers nums, the function must return a string with the complete notation of the expression that returns the greater result (adding the equal sign after the expression and the result after the equal sign). For the example above, the result will be:
greaterPermutation("(a - b) * c", [1, 2, 3]) ➞ "(3 - 1) * 2 = 4"
If an expression returns a float number as result, round it to the nearest hundredth.
greaterPermutation("(a - b) * c", [1, 2, 3]) ➞ "(3 - 1) * 2 = 4"
greaterPermutation("a ** b - c", [2, 3, 1]) ➞ "3 ** 2 - 1 = 8"
greaterPermutation("a % b + (c * 2)", [3, 1, 2]) ➞ "1 % 2 + (3 * 2) = 7"