title: Algorithm to Derive All Possible Math Expressions In a Set To get a Target Value
body: <p>I am new to Swift Programming, and while I could figure the rest of this out for this app I have floating in my head, I'm having a hard time figuring out how to derive a algorithm that could handle this problem:</p>
  
  <p>Given a set of 4 values (probably best to use Double because some can even be fractions), derive all possible combinations that return a result of a target value--in my case, 24.</p>
  
  <p>For example, a+b+c+d, a+b+d+c, a+d+b+c, d+a+b+c, and all arrangements of that set, plus all possible mathematical operators such as (a*b)^(c-d) or (a+b+c)/d.</p>
  
  <p>I was able to find this article, but it doesn't quite match what I'm looking for, especially as order doesn't matter for me
  <a href="https://stackoverflow.com/questions/29734145/number-of-ways-to-sum-the-items-in-a-set-to-get-a-target-value-order-matters">Number of ways to sum the items in a set to get a target value - Order matters</a></p>
  
  <p>so for example, I could manually do each combination this way:</p>
  
  <pre><code>if a + b + c + d == 24 {
    print("\a + \b + \c + \d")
  }
  </code></pre>
  
  <p>My goal is for the user to enter 4 values and let IOS generate a list of all possible mathematical expressions that result in 24.</p>
  
  <p>Patrick</p>