Square Deal

From programming_contest
Jump to navigation Jump to search

This problem asks us if we can arrange 3 input rectangles to form a square.

Note that there are very few overall configurations of the rectangles.

  1. identify the 6 edge lengths of the 3 rectangle
  2. iterate through any pairs of matching edge lengths
  3. "simulate" joining the two triangles
  4. check if either of the two edge lengths of the third rectangle match either of them from the newly formed rectangle
  5. check if the combination forms a square

One could also (loosely):

  1. calculate the total area of the rectangles, and thus the area and side length of the square
  2. evaluate if any sum of the rectangles edges matches that of the square
  3. evaluate whether the rectangles assembled in that fashion form a valid square