We are given a list of integers p1, ..., pk (not necessarily distinct) where each has a value between 1 and 9, inclusive. Using each of the p1, ..., pk exactly once, we can form concatenations of digits, to achieve a new list of numbers; we then output the product of this new list. The goal is to maximize this product by choosing the best concatenations of digits.
For example, we are given the list: 2 3 2 (separated by spaces). We can form the following concatenations:
2 3 2(product of these concatenations is
23 2(product is
32 2(product is
22 3(product is
Since the largest product that we can form of concatenations is 66, we output that.
- There must be at least one multiplication (i.e., you cannot just concatenate all of the digits and output that).
- You cannot use any other operators other than multiplication, or insert parentheses, etc.
- Assume that the list of integers given is separated by spaces, and all integers have values between 1 and 9.
Shortest code (in bytes) wins!
1 2 3; Output:
2 5 9; Output:
1 2 3 4; Output: