This time, the challenge is this: Given a list of integers and a single integer argument output a parenthesized expression that sums to the individual integer provided, with the basic arithmetic operations (+, -, /, *)
1 parenthesize([1, 20, 2], 11) => (1 + (20 / 2))
2 parenthesize([1, 2, 3, 4], 10) => (1 + 2 + 3 + 4)
In order to make things interesting, we'll be running this one as a round of Code Golf. That is, you're looking to do this in the smallest number of characters (not counting whitespace).
-- The function signature is not added to the count, and it must have 2 and only 2 parameters (the list of numbers and the integer)
-- It must be a single top-level function (nested helper functions are fine)
-- "import" and "import ... as" are acceptable
-- Your function must handle the case when the expression is not parenthesizable.
-- There must be outer brackets on every expression e.g. (5 + 4 + 3), (6 * (2 + 1))
-- Order of arithmetic operations are PEDMAS or BODMAS/BIDMAS basically anything in BRACKETS first then DIVISION then MULTIPLICATION then ADDITION then SUBTRACTION
-- And for those wondering, the Simown constraint is in effect.
Any questions leave a comment here and we'll get back to you. Remember, you have 2 weeks to complete this challenge before the next one is posed.
And as always, please post your solutions in spoiler tags as a courtesy to those who are still working on it.
That's it! Happy Challenging!
This post has been edited by Simown: 19 January 2013 - 02:29 PM
Reason for edit:: Fixing some terminology