# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1184: Church-draughtsmanship

From New Scientist #2340, 27th April 2002 [link]

My young nephew recently asked me to draw him a church. He gave me a sheet of A4 paper, and I began by drawing a square. I next added an isosceles triangle, using the whole of the top of the square as its base. To the whole of one side of the square I then added a rectangular nave. Of the three shapes, the rectangle occupied the largest area. The four different constituent dimensions were each a whole number of centimetres, these dimensions being the sides of each shape and the vertical height of the triangle. The areas of the three shapes added together produced a total which was perfectly divisible by each of the four dimensions.

What were the overall length and overall height of my church?

[enigma1184]

### 3 responses to “Enigma 1184: Church-draughtsmanship”

1. Jim Randell 18 January 2016 at 8:32 am

A4 paper is 210mm × 297mm. So the diagram must fit in a 21cm × 29cm rectangle.

This Python program runs in 34ms.

```from enigma import irange, is_square, printf

# consider the side of the square (must be divisible by 2)
for a in irange(2, 20, step=2):
# area of the square
A = a * a

# consider the height of the triangle (a + h <= 29)
for h in irange(1, 29 - a):
# area of the triangle
B = (a // 2) * h
# length of the sloping sides of the triangle
b = is_square(A // 4 + h ** 2)
if b is None: continue

# consider the length of the rectangle
for c in irange(1, (29 if a + h < 22 else 21) - a):
# area of the rectangle
C = a * c
if not(C > A and C > B): continue

# total area of the church
t = A + B + C
if any(t % d > 0 for d in (a, h, b, c)): continue

printf("a={a} h={h} b={b} c={c}, A={A} B={B} C={C}, t={t}")
```

Solution: The overall length of the church is 18 cm. The overall height of the church is 10 cm.

Here’s a scale diagram of the church:

The large dashed rectangle corresponds to the A4 sheet. The dimensions are in cm.

• geoffrounce 19 January 2016 at 4:38 pm
```def is_sq(n):
for a in range(2, int(n**0.5) + 1):
if a * a == n:
return True
return False

for a in range(2, 21, 2):
# find height of triangle on square (h)
for h in range(1, 21):
# hypotenuse must be an integer
if is_sq(h**2 + (a/2)**2):
hyp = int((h**2 + (a/2)**2) ** 0.5)

for b in range(a, 21, 2):  # b is rectangle length
# find the three areas and the total area
sq, tri, rect = a * a, a//2 * h, a * b
tot_area = sq + tri + rect

# check all dimensions divide total area
if all(tot_area % x == 0 for x in (a, hyp, b, h)):
# check church drawing dimensions are less than A4 paper size
if a + b < 29 and a + h < 21:
print('Church length = {} cm, Church height = {} cm'
.format (a + b, a + h))

# Church length = 18 cm, Church height = 10 cm
```
• geoffrounce 21 January 2016 at 3:15 pm

I also found a solution in MiniZinc. If we remove the constraint that the rectangle must be bigger than the square, there are two more cases where the arithmetic otherwise works ok.

```% Dimension variables
var 2..22 : a;    % square side
var 2..22 : b;    % rectangle long dimension
var 2..22 : h;    % height of triangle;
var 2..22 : hyp;  % hypotenuse of triangle

% Church main dimensions
var 2..29 : clength;   % length of church
var 2..22 : cheight;   % height of church

% Area variables
var 2..300: tri;       % area of triangle
var 2..500: rect;      % area of rectangle
var 2..500: sq;        % area of square
var 2..600: tot_area;  % total area

include "globals.mzn";

solve satisfy;

% dimensions a and b are even numbers
constraint a mod 2 == 0 /\ b mod 2 == 0;

constraint b > a;  % rectangle is larger than the square

% hypotenuse is an integer
constraint h * h + (a div 2 * a div 2) == hyp * hyp;

% total area = square + rectangle + triangle
constraint tot_area = (a * a) + (a * b) + (a div 2 * h);

% total area is divided by all dimensions
constraint tot_area mod a == 0 /\ tot_area mod b == 0
/\ tot_area mod h == 0 /\ tot_area mod hyp == 0;

constraint clength = a + b /\ cheight = a + h;

% drawing must fit on A4 paper (29 cm by 21 cm)
constraint a + b < 29 /\ a + h < 21;

output [show("Length = "), show(clength), show(" Height = "),show(cheight)];
% Length = 18 Height = 10

% Analysis
% --------
% without b > a condition, all solutions are:
% %output [show(a)," ", show(b)," ", show(h)," ", show(hyp), " ",show(clength)," ", show(cheight)];
% 6 2 4 5 8 10
% 6 12 4 5 18 10
% 12 4 8 10 16 20

%  a   b  h  hyp | length height | sq tri rect tot-area
%------------------------------------------------------
%  6   2  4   5       8     10     36  12  12    60
%  6  12  4   5      18     10     36  12  72   120  << enigma solution (b > a)
% 12   4  8  10      16     20    144  48  48   240

```