title: What is the minimum number of case (or if/else) statements required to calculate all unknown values corresponding to properties of an object?
body: <p>Consider a right-angle triangle, which has the properties</p>
  
  <ul>
  <li>Hypotenuse (side)</li>
  <li>Adjacent (side)</li>
  <li>Opposite (side)</li>
  <li>Area</li>
  </ul>
  
  <p><img src="https://www.mathsteacher.com.au/year10/ch15_trigonometry/01_ratios/Image3119.gif" alt="triangles"></p>
  
  <p>Given any 2 of these properties, it is always possible to calculate the value of the other 2. My question relates to what the most efficient/elegant way of doing this is.</p>
  
  <p>At present, the only way of doing this that I can think of is to use (4C2)*2 = 12 case statements, each relating to a possible combination of inputsa that may be provided.</p>
  
  <p>For example, using python you might have something like</p>
  
  <pre><code>class RightAngleTriangle():
      def __init__(this, propertyType1, propertyValue1, propertyType2, propertyValue2):
          this.adjacent = 0
          this.opposite = 0
          this.hypotenuse = 0
          this.area = 0
      if (propertyType1 == "adjacent" and propertyType2 == "opposite"):
          this.adjacent = propertyValue1
          this.opposite = propertyValue2
          this.hypotenuse = (propertyValue1**2 + propertyValue2**2)**0.5
          this.area = (propertyValue1 * propertyValue2)/2
      elif (propertyType1 == "opposite" and propertyType2 == "adjacent"):
          this.adjacent = propertyValue2
          this.opposite = propertyValue1
          this.hypotenuse = (propertyValue1**2 + propertyValue2**2)**0.5
          this.area = (propertyValue1 * propertyValue2)/2
      elif (propertyType1 == "adjacent" and propertyType2 == "hypotenuse"):
          this.adjacent = propertyValue1
          this.hypotenuse = propertyValue2
          this.opposite = (propertyValue2**2 + propertyValue1**2)**0.5
          this.area = (this.opposite * this.adjacent)/2
  </code></pre>
  
  <p>...and so on...</p>
  
  <p>You could then create your triangle object, and print its four properties, using code (in this case python) like the below.</p>
  
  <pre><code>t1 = RightAngleTriangle("adjacent", 10, "opposite", 12)
  print(t1.adjacent)
  print(t1.opposite)
  print(t1.hypotenuse)
  print(t1.area)
  </code></pre>
  
  <p>This is hideous. Is there a more eligant solution to this problem?</p>