Algorithm - Represent a certain integer by expression of 4 digits
This is my problem: "I give you the 4 digits 1, 2, 3, 4. I want you to use
all four of these digits to create mathematical expressions for number 1,
2, 3 etc. The winner will be the entry that produces for the longest range
of number from 1 upwards. You can use the mathematical symbols + - * / .
In addition brackets and square root are allowed. Please note that you can
place the digits side by side to form a 2 or 3 digit number. Examples
would be:
1 = ( 3/1 ) - ( 4/ 2 )
2 = ( 2 * 3 ) – ( 4/1)
3 = 21 / ( 3 + 4 )
4 = "
So I need an algorithm which:
`Input: an integer`
`Output: an expression formed by digits 1,2,3,4`
Right now I can only think of brute force algorithm:
First try the expression which formed by only one-digit number. In this
expression, try all 4 operators +,-,*,/ in every possible position. Then
try to put more bracket.
Then try try the expression which formed by two-digit number and two one
digit number...
But implement this algorithm is hard because I cannot think of all the cases.
Anyone got better ideas?
No comments:
Post a Comment