# Enigmatic Code

Programming Enigma Puzzles

## Enigma 182: ‘I would if I could’

From New Scientist #1327, 14th October 1982 [link]

“I would if I could, but I’m sorry I can’t”
I felt that I had to say this to my Aunt.
She seemed to expect me to lend her some cash
And knowing my Aunt that would surely be rash.
I happen to know what her overdraft is;
My Uncle’s is large, hers is much more than his.
Her husband, my Uncle, in fact owed the bank
A number of pounds which was, let’s be frank,
Sixty-three more than my overdraft then.
Aunty’s and mine are two-hundred-and-ten;
Between them, I mean, and I’d like you to see,
When I say “much”, Aunt’s is Uncle’s times three —
Or as near to three as it can be,
Bearing in mind this vital fact,
The pounds we owe are all exact.

What are the overdrafts of my Aunt, my Uncle and myself?

[enigma182]

### 4 responses to “Enigma 182: ‘I would if I could’”

1. Jim Randell 8 April 2014 at 12:13 am

This Python code runs in 32ms.

```from enigma import irange, Accumulator, printf

# the three overdrafts are A, U, M
# A > U > M, U = 63 + M
#
# (1) U = 63 + M
# (2) A + M = 210
# (3) A/U ~ 3

# find the closest ratio to three
m = Accumulator(fn=min)
for A in irange(106, 209):
M = 210 - A
U = 63 + M
if not(A > U): continue

r = float(A) / float(U)
m.accumulate_data(abs(3.0 - r), (A, U, M))

printf("[A={A} U={U} M={M} r={r}]")

(A, U, M) = m.data
printf("A={A} U={U} M={M} [r={r}]", r=float(A) / float(U))
```

Solution: My Aunt’s overdraft is £205. My Uncle’s overdraft is £68. My overdraft is £5.

The actual ratio of the Aunt’s and Uncle’s overdrafts is 3 + 1/68 (≈ 3.015).

2. geoffrounce 3 September 2016 at 10:56 am
```% A Solution in MiniZinc
include "globals.mzn";

var 0..1000: Aunt;  var 0..1000: Uncle;  var 0..1000: Me;

constraint alldifferent([Aunt, Uncle, Me])
/\ Aunt > 0 /\ Me > 0 /\ Uncle > 0;

constraint Aunt + Me == 210 /\ Aunt > Uncle
/\ Uncle == Me + 63 /\ Aunt div Uncle == 3;

solve satisfy;
output [show(Aunt) ++ " " ++ show(Uncle) ++ " " ++ show(Me)];

.```

This Enigma was set for multiple outputs in the MiniZinc configuration and gave the following results – I added the last column:
Aunt Uncle Me 3 * Uncle
209 64 1 (3*64 = 192)
208 65 2 (3*65 = 195)
207 66 3 (3*66 = 198)
206 67 4 (3*67 = 201)
205 68 5 (3*68 = 204)

The last condition in the Enigma gives the solution:
Aunt = 205, Uncle = 68 and Me = 5

• Jim Randell 3 September 2016 at 11:09 am

I think we can solve this using the minimize parameter to satisfy to get the A/U value closest to 3 directly.

```% overdraft amounts for Aunt, Uncle, Me
var int: A;
var int: U;
var int: M;

% A > U > M > 0
constraint A > U /\ U > M /\ M > 0;

% U = 63 + M
constraint U = 63 + M;

% A + M = 210
constraint A + M = 210;

% find when A/U is closest to 3
solve minimize abs(A - 3 * U);

% output solution
output [ "A = " ++ show(A) ++ ", U = " ++ show(U) ++ ", M = " ++ show(M) ];
```
• geoffrounce 3 September 2016 at 11:35 am

Yes, good point.

Although the <minimize> constraint produces the correct single solution,
It still gives the same multiple solutions for a multiple configuration output, which seems a bit odd.

I thought MiniZinc produced a simple, neat solution for this Enigma