CS4HS Summer Program for HS Teachers

Triangles in a grid

July 2011
Problem 3

Two triangles are congruent if they have the same shape and size. In other words, they are congruent if and only if one can be transformed into the other by a combination of translations, rotations, and reflections.

The input file DATA3.txt will contain 5 lines, where each line has 4 integers separated by single spaces, 0 ≤ A, B, X, Y ≤ 8, where (A, B) specifies the bottom-left corner of a rectangle and (X, Y) specifies the top-right corner of a rectangle in the Cartesian plane.

The output file OUT3.txt will contain 5 lines. Each line contains the number of different (not congruent) triangles contained in the rectangle. Only consider triangles whose vertices have integer coordinates inside the box specified by (A, B) and (X, Y).

Sample Input (only first 2 shown):
0 0 3 5
2 3 8 6
Sample Output (only first 2 shown):
108
160