11
1
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 is12
)23 2
(product is46
)32 2
(product is64
)22 3
(product is66
)
Since the largest product that we can form of concatenations is 66, we output that.
Rules:
- 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!
Test cases:
Input: 1 2 3
; Output: 63
(i.e., 21*3
)
Input: 2 5 9
; Output: 468
(52*9
)
Input: 1 2 3 4
; Output: 1312
(41*32
)
Should we write a whole program or a function taking input parameters and returning the result is also fine? – randomra – 2015-05-10T21:58:19.163
@randomra Yes, that's fine. – Ryan – 2015-05-10T22:01:26.200
For each pair of numbers a,b, the product a* b.is less than the simple concatenation ab (= a*10^(digits of b)+b). So just 1 product (as it's mandatory). Add this: http://codegolf.stackexchange.com/q/49854/21348
– edc65 – 2015-05-11T14:35:21.803