0
$\begingroup$

You are given the following problem: Given the digits 1-9 and the four basic mathematical operators +, -, * and /, find the shortest sequence that evaluates to a target integer.

For example, given 10 as the target, either of the following would be acceptable as evaluating to the correct number, but obviously the second isn't the shortest...

2 * 5
1 * 4 * 2 + 2

What I would like to know is, is there a way of finding the minimum number of digits needed? I know you can make a sequence of as long as you want, but I want to know the shortest length, or at least some bound.

I know that you can always produce a sequence as follows...

1 + 1 + ... + 1 + 1

...where there are enough 1s to add up to the target. This has length n. You can also do...

9 + 9 + ... + 9 + r

...where the number of 9s is the integer division of 9 into the target and r is the remainder, which gives a sequence of length (n % 9) + 1 where % is modular division, but these sequences can get quite large. I would like to know if there is a lower bound.

In case anyone is wondering, the background to this is that I'm writing some code to solve this using a genetic algorithm, and I want to compare the performance with solving it by brute force, ie churning through all possibilities one by one. I would like to know a bound that I can use to limit the number of sequences the brute force code has to check.

  • 0
    You want the shortest length or the upper bound to no. of sequences you need to check?2017-01-14
  • 0
    @Gyanshu My main interest is an upper bound to the length of sequence, from which I can work out the maximum number of sequences I would need to check. However, if I can find the shortest length, that answers the same question. I'm not sure of the difference between the two really, as they both lead to the same information.2017-01-15
  • 0
    Anyone able to help?2017-01-18

0 Answers 0