7
0
Given 4 numbers n1, n2, n3, n4, and a goal n5, obtain n5 using n1 through n4 combined with any operations.
Eg. Given four numbers 2,3,4,5 and the goal as 8, output (one of many) is 2-3+4+5
EDIT: This is a variation of a game played at my son's school. Paranthesis, powers, unary operations (log, factorial) are allowed; the expressions tend to get complicated. However, unary operations can be applied only once on a number. Essentially, the tree should be:
goal
/\
/ \
/ \
expression1 expression2
/\ /\
/ \ / \
/ \ / \
term1 term2 term3 term4
where term#i is either
1. one of the numbers, or
2. one of the numbers with an unary operation.
Does factorial count as an operation? – Eelvex – 2011-03-09T08:25:30.647
Can output need parentheses? (it seems like a valid way to combine with the operations, but neither your example nor the current posted answers support that) For example solving 5 with 10,1,1,0. – J B – 2011-03-09T08:49:05.813
BTW, is this code golf at all? – J B – 2011-03-09T20:50:33.367
@CMR: You are expected to tag a question with a type-of-challange tag; either code-golf or code-challenge (and possibly others eventually). Given the nature of the answers so-far, I'm going to apply [code-golf], and you should change it if that is not what you meant. – dmckee --- ex-moderator kitten – 2011-03-11T19:23:07.447
I assume "4+4" is invalid since it repeats a number and doesn't use 2,3,5? – barrycarter – 2011-03-14T03:10:54.937
All numbers to be used, once and only once. – CMR – 2011-03-14T13:03:17.673