title: Is my math over complicated, it works
body: <p>I've made a function to perform a calculation against four fields. Then outputs the that calculation to a receiver field. 
  The math is fairly simply in concept.
  The receiver field is the remainder of the lowest int from the next lowest int.
  For instance the app reads values 2, 5 , 6, 8 from user input. 
  Receiver field should equal(3)</p>
  
  <p>I have implemented NSSet to remove any duplicates than re-stack the set into an array for ease of reading and the values and custom control. </p>
  
  <p>The math section of the function seems like over kill. Is there a more elegant way to perform this other than what I have built? It works it's just ugly and probably not the correct path.</p>
  
  <p>Any help is appreciated. </p>
  
  <pre><code>// set of strings populated from a sibling View so i used a singleton to sync.
  NSArray *myArray = [[NSArray alloc] initWithObjects:[StringLinker sharedManager].singcol1Row1String,
                                                      [StringLinker sharedManager].singcol1Row2String,
                                                      [StringLinker sharedManager].singcol1Row3String,
                                                      [StringLinker sharedManager].singcol1Row4String,nil];
  NSSet *set = [NSSet setWithArray:myArray];
  NSLog(@"mySet count: %d", [set count]);
  
  NSMutableArray *newArray = [NSMutableArray arrayWithArray:[set allObjects]];
  // define locals 
  int i;
  int tempV;
  id *objects;
  int  v1Col1=0;
  int  v2Col1=0;
  int  v3Col1=0;
  int  v4Col1=0;
  // create helpers
  NSUInteger count = [newArray count];
  objects = malloc(sizeof(id) * count);
  [newArray getObjects:objects];
  // check the correct id and location
  for (i = 0; i &lt; [newArray count]; i++) {
      tempV = [[newArray objectAtIndex:i]intValue];
      NSLog(@"current objectAtIndex = %i id = %i",i,tempV);
  }
  NSLog(@"count of new Array = %d",count);
  // assign our controlled items. and make string into a Value
  if (count &gt;= 1) { v1Col1 = [[newArray objectAtIndex:0]intValue];}
  if (count &gt;= 2) { v2Col1 = [[newArray objectAtIndex:1]intValue];}
  if (count &gt;= 3) { v3Col1 = [[newArray objectAtIndex:2]intValue];}
  if (count &gt;= 4) { v4Col1 = [[newArray objectAtIndex:3]intValue];}
  
  // then do raw calculations
  if ( count ==2) {
      if (v1Col1 &lt; v2Col1) { _master1PinsCol1 = v2Col1 - v1Col1;}
      if (v2Col1 &lt; v1Col1) { _master1PinsCol1 = v1Col1 - v2Col1;}
  }
  if ( count ==3) {
      if ((v1Col1 &lt; v2Col1) &amp;&amp; (v2Col1 &lt; v3Col1)) { _master1PinsCol1 = v2Col1 - v1Col1;}
      if ((v1Col1 &lt; v2Col1) &amp;&amp; (v3Col1 &gt; v2Col1)) { _master1PinsCol1 = v2Col1 - v1Col1;}
      if ((v1Col1 &lt; v2Col1) &amp;&amp; (v3Col1 &lt; v2Col1)) { _master1PinsCol1 = v3Col1 - v1Col1;}
      if ((v2Col1 &lt; v1Col1) &amp;&amp; (v1Col1 &lt; v3Col1)) { _master1PinsCol1 = v1Col1 - v2Col1;}
      if ((v2Col1 &lt; v3Col1) &amp;&amp; (v3Col1 &lt; v1Col1)) { _master1PinsCol1 = v3Col1 - v2Col1;}
  }
  if (count &gt;=4){
      if ((v1Col1 &lt; v2Col1) &amp;&amp; (v1Col1 &lt; v3Col1) &amp;&amp; (v1Col1 &lt; v4Col1)) { 
          if ((v2Col1 &lt; v3Col1) &amp;&amp; (v2Col1 &lt; v4Col1)) {_master1PinsCol1 = v2Col1-v1Col1;}
          if ((v3Col1 &lt; v2Col1) &amp;&amp; (v3Col1 &lt; v4Col1)) {_master1PinsCol1 = v3Col1-v1Col1;}
          if ((v4Col1 &lt; v2Col1) &amp;&amp; (v4Col1 &lt; v3Col1)) {_master1PinsCol1 = v4Col1-v1Col1;}
      }
      if ((v2Col1 &lt; v1Col1) &amp;&amp; (v2Col1 &lt; v3Col1) &amp;&amp; (v2Col1 &lt; v4Col1)) {
          if ((v1Col1 &lt; v3Col1) &amp;&amp; (v1Col1 &lt; v4Col1)) {_master1PinsCol1 = v1Col1-v2Col1;}
          if ((v3Col1 &lt; v1Col1) &amp;&amp; (v3Col1 &lt; v4Col1)) {_master1PinsCol1 = v3Col1-v2Col1;}
          if ((v4Col1 &lt; v1Col1) &amp;&amp; (v4Col1 &lt; v3Col1)) {_master1PinsCol1 = v4Col1-v2Col1;}
      }
      if ((v3Col1 &lt; v1Col1) &amp;&amp; (v3Col1 &lt; v2Col1) &amp;&amp; (v3Col1 &lt; v4Col1)) {
          if ((v1Col1 &lt; v2Col1) &amp;&amp; (v1Col1 &lt; v4Col1)) {_master1PinsCol1 = v1Col1-v3Col1;}
          if ((v2Col1 &lt; v1Col1) &amp;&amp; (v2Col1 &lt; v4Col1)) {_master1PinsCol1 = v2Col1-v3Col1;}
          if ((v4Col1 &lt; v1Col1) &amp;&amp; (v4Col1 &lt; v2Col1)) {_master1PinsCol1 = v4Col1-v3Col1;}
      }
      if ((v4Col1 &lt; v1Col1) &amp;&amp; (v4Col1 &lt; v2Col1) &amp;&amp; (v4Col1 &lt; v3Col1)) { 
          if ((v1Col1 &lt; v2Col1) &amp;&amp; (v1Col1 &lt; v3Col1)) {_master1PinsCol1 = v1Col1-v4Col1;}
          if ((v2Col1 &lt; v1Col1) &amp;&amp; (v2Col1 &lt; v3Col1)) {_master1PinsCol1 = v2Col1-v4Col1;}
          if ((v3Col1 &lt; v1Col1) &amp;&amp; (v3Col1 &lt; v2Col1)) {_master1PinsCol1 = v3Col1-v4Col1;}
      }
  }
  
  
  NSLog(@"***********************************Col1 Master1 = %.0f",_master1PinsCol1);
  </code></pre>