title: Python algorithm/function: return all of the operational combinations of the digits of an input number which equal a target number
body: <p>I am tasked to produce a function f which, given an input number and target number, will return all operational combinations (+, -, /, * and joining digits) of the input which make the target number. For example if the input and target numbers are 115 and 16, the program should return <code>11+5=16</code>. Inputs f(123,6) should yield <code>1+2+3=6</code> and <code>1*2*3=6</code>. f(12301,6) should return <code>1+2+3+0*1=6</code>, <code>1+2+3-0*1=6</code>, <code>1*2*3+0*1=6</code>, <code>1*2*3-0*1=6</code>, <code>1+2*3+0-1=6</code>, and <code>1+2*3-0-1=6</code>.</p>
  
  <p>Here is my attempt so far. I tried to approach this recursively, but am having trouble developing a solid algorithm. Is a recursive algorithm the correct way to approach this problem?</p>
  
  <pre><code>"""
  creates a list of the integers associated with input number and returns all the
  ways that list of numbers can be ordered with +-*/ operators to form target_num
  base specifies which number system is being used (base 10 is default)
  """
  TASKS = ['add','mul','sub','div','con']
  def consec_op_types(num_in, target_num, base = 10):
  
      # get digits
      digits = []
      while num_in &gt;1:
          next_smallest_number = num_in % base
          num_in = num_in / 10
          digits.append(next_smallest_number)
      digits.append(num_in)
      digits.reverse()
  
      '''
      A recursive scheme is used to find the combinations.
      Each function call in turn calls +-/* operators as well as just using this number with the one next to it
      '''
  
      # accepts list of operators used, references digits from above
      def show_results(vals):
          # print [item for sublist in zip(vals,digits) for item in sublist], ' = ', target_num
          print ''.join([str(v) for v in vals]), '=', target_num
  
  
      def find_number(num_list,total= 0,task= 0, result = []):
          print 'total:',total
          if num_list == [] :
          #    if total != 0: print total, result
              if total ==target_num: show_results(result)
              return
  
          if total==0:
             if task == TASKS[3] or task == TASKS[1]: total = 1
  
          #print "result = result+['+']",result+['+']
          #print 'total:',total
          if task in TASKS:
              current_num = num_list[0]
              num_list = num_list[1:]
              result.append(current_num)
          if task == TASKS[0]:
              return find_number(num_list, total + current_num,  0,  result+['+'])
  
          if task == TASKS[1]:
              return find_number(num_list, total * current_num,  task = 0,result = result+['*'])
  
          if task == TASKS[2]:
              return find_number(num_list, total + current_num, task = 0, result = result+['-'])
  
          if task == TASKS[3]:
              if current_num != 0: return find_number(num_list, total / current_num, task = 0, result = result+['/'])
  
          if task == TASKS[4] and len(num_list)&gt;1:
              print 'ok.... num_list is ',num_list,' and current num is ',current_num
              print '---&gt;',[10*current_num + num_list[0]]+num_list[1:]
  
              return find_number( [10*current_num + num_list[0]] + num_list[1:], 
                                   total,  0, result[:-1])
  
          #find_number(num_list, total, TASKS[0], result)
          for tk in TASKS:
              find_number(num_list, total, tk, result)
      find_number(digits)
  
  # Object oriented idea (Not used, here to show I tried to implement it)
  # class digit_tree_node:
  #     def __init__(self, total = 0, recs = [], real_num):
  #         self.value = total
  #         self.records = recs
  #         self.true_val = real_num
  # 
  #     def add_num(self, new_num):
  #         addition = digit_tree_node(self.value+new_num)
  # # #         
  </code></pre>