title: Best way to calculate several iterations with different parameters?
body: <p>I am making a program that calculates what requirements need to be met in order to win an achievement from a game.</p>
  
  <p>An achievement can have multiple levels, each with different requirements, and a player could have already fulfilled part of the requirements. So, for example:</p>
  
  <p>Achievement A level 1 requires 10 rat tails
  <br/>Achievement A level 2 requires 8 rat tails and 2 wolf tails</p>
  
  <p>In order to get Achievement A level 2 a player would need a total of 18 rat tails and 2 wolf tails, but if he already has 5 rat tails I'd like the program to tell him he needs 13 rat tails and 2 wolf tails.</p>
  
  <p>Therefore I am looking for a mathematical equation or programming method that can easily (maybe in a loop) calculate the requirements of each level and substract what the player already has, in other words some sort of a loop that calculates a different equation each time. The reason for that is that a player can choose which level he wants, so he can choose "Tell me what I need for level 1" or "Tell me what I need for level 10" and after his selection the program needs to do the total calculation, which I can do by hand like:</p>
  
  <pre><code>int wolftail, rattail;
  int wolftailInv, rattailInv;
  if (level == 1)
  {
    wolftail = 0;
    rattail = 10 - rattailInv;
  }
  
  if (level == 2)
  {
    wolftail = 2 - wolftailInv;
    rattail = 18 - rattailInv;
  }
  </code></pre>
  
  <p>Or, in other words the mathematical equation for the total for level 2 would be (let's for a moment ignore what the player already has):</p>
  
  <pre><code>Level 2 = Level 1 + 2x wolftail + 8x rattail
  Level 1 = 10x rattail
  =&gt;
  Level 2 = 10x rattail + 2x wolftail + 8x rattail
  </code></pre>
  
  <p>while the equation for level 1 would be only:</p>
  
  <pre><code>Level 1 = 10x rattail
  </code></pre>
  
  <p>So I am wondering if there is a mathematical or programmatical method which could take into consideration the different mathematical equations for each separate level and automatically add them, but only the ones needed. In effect I am looking for the programmatical equivalent of substitution of the type:</p>
  
  <pre><code>x = 2y + apples
  y = banana
  =&gt;
  x = 2x banana + apples
  </code></pre>
  
  <p>This is a simple example, but the reason a simple sum won't work, because there are levels like this, also:</p>
  
  <pre><code>Level 6 = Level 5 + strangestuff
  Level 5 = Level 4 + otherstuff
  Level 4 = Level 3 + otherstuff
  Level 3 = Level 2 + zzz
  </code></pre>
  
  <p>So the sum for Level 6 would be:</p>
  
  <pre><code>Level 6 = Level 2 + zzz + 2x otherstuff + strangestuff
  </code></pre>
  
  <p>But if a player already has Level 3 achieved the equation changes to:</p>
  
  <pre><code>Level 6 = 2x otherstuff + strangestuff
  </code></pre>
  
  <p>So I need mathematical substitution in c# and/or something that takes into account the different components that make a sum and can take them out, when needed.</p>