# Enigmatic Code

Programming Enigma Puzzles

## Enigma 361: How many furlongs to the mile?

From New Scientist #1510, 29th May 1986 [link]

“How can one inch, one foot, one yard, one furlong and one mile be only 249 inches?” asked Albert, who was looking at a calculation in the Tarizania University library.

“Simple,” replied the librarian. “That sum was done before we adopted the English system of metrication.”

“How many furlongs to the mile were there?”

“Perhaps you would like to work out that prime number if I tell you that there were more furlongs to the mile than yards to the furlong, more yards to the furlong than feet to the yard and more feet to the yard than inches to the foot,” said the librarian.

What is the answer to Albert’s question?

[enigma361]

### 2 responses to “Enigma 361: How many furlongs to the mile?”

1. Jim Randell 9 September 2016 at 8:45 am

I assumed that the multipliers in each case were integers.

This Python program runs in 38ms.

```# if:
#   f = number inches in a foot
#   y = number of feet in a yard
#   F = number of yards in a furlong
#   M = number of furlongs to a mile (prime)
#
# 1 + f + yf + Fyf + MFyf = 249
#
# f + yf + Fyf + MFyf = 248
#
# f(1 + y(1 + F(1 + M))) = 248
#
# M > F > y > f > 1

from enigma import divisors, is_prime, printf

# consider divisors of 248
for f in divisors(248):
r1 = (248 // f) - 1
if not(f > 1 and r1 > 1): continue

for y in divisors(r1):
r2 = (r1 // y) - 1
if not(y > f and r2 > 1): continue

for F in divisors(r2):
M = (r2 // F) - 1
if not(M > F > y and is_prime(M)): continue

printf("f={f} y={y} F={F} M={M}")
```

Solution: There are 7 furlongs to the mile.

There are 2 inches in a foot. 1 foot = 2 inches.

There are 3 feet in a yard. 1 yard = 6 inches.

There are 5 yards in a furlong. 1 furlong = 30 inches.

There are 7 furlongs in a mile. 1 mile = 210 inches.

1 mile + 1 furlong + 1 yard + 1 foot + 1 inch = (210 + 30 + 6 + 2 + 1) inches = 249 inches.

Without the restriction that M is prime there is an additional solution of f=2, y=3, F=4, M=9.

• Jim Randell 9 September 2016 at 8:50 am

I’ve also made a Python library that runs a MiniZinc model and parses the output, which means you can do any additional post-processing and output using Python.

This Python program uses a MiniZinc model to generate candidate solutions, then the Python code checks that M is prime, and produces the output.

Overall run-time for this program is 116ms.

```from minizinc import MiniZinc
from enigma import is_prime, printf

model = """

include "globals.mzn";

var int: f;
var int: y;
var int: F;
var int: M;

constraint f * (1 + y * (1 + F * (1 + M))) = 248;

constraint increasing([1, f, y, F, M]);
constraint alldifferent([1, f, y, F, M]);

solve satisfy;

"""

for (f, y, F, M) in MiniZinc(model).solve(result="f y F M", solver="mzn-gecode -a"):
if is_prime(M):
printf("f={f} y={y} F={F} M={M}")
```

The code for minizinc.py is available on GitHub.