# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1128: Daffodils

From New Scientist #2284, 31st March 2001 [link]

Saul Tregenza is a market gardener. He has a field in which he decided that it could be profitable to plant equal rows of daffodils. On a whim prompted by helping with his daughter’s homework, he decided that the number of rows and the number of bulbs in each row should be prime, and that all the digits that would form the two numbers and their product would be different.

Luckily, he found that the field is long enough to hold the maximum possible number of plants under these whimsical conditions.

What was the maximum possible number of bulbs he could plant?

[enigma1128]

### 2 responses to “Enigma 1128: Daffodils”

1. Jim Randell 13 February 2017 at 8:41 am

This Python program uses some useful string functions from the enigma.py library. It runs in 80ms.

```from enigma import Primes, is_duplicate, concat, Accumulator, printf

# the largest possible factor involved is 4-digit

# primes less than 10000 with no repeated digits
primes = list(p for p in Primes(10000) if not is_duplicate(p))

# accumulate result, find the maximum product
r = Accumulator(fn=max)

# select two primes p and q
for q in primes:
for p in primes:
if not(p < q): break
# find their product
n = p * q
s = concat(p, q, n)
# there should be 10 digits or fewer
if len(s) > 10: break
# and no repeated digits
if not is_duplicate(s):
r.accumulate_data(n, (p, q))
printf("[{n} = {p} * {q}]")

(n, (p, q)) = (r.value, r.data)
printf("max = {n} = {p} * {q}")
```

Solution: The maximum possible number of bulbs is 65,821 (= 7 × 9403).

2. Hugh Casement 13 February 2017 at 12:10 pm

There seem to be remarkably few numbers of bulbs > 10000 that leave us with no repeated digit,
at least when planted in a long narrow strip of 2, 3, 5, or 7 rows.
I found only 17082 = 3 × 5694, 20457 = 3 × 6819, 20754 = 3 × 6918,
21658 = 7 × 3094, 24507 = 3 × 8169, 27504 = 3 × 9168, 28651 = 7 × 4093,
65128 = 7 × 9304, 65821 = 7 × 9403.
Of those, only 4093 and 9403 are prime.
I haven’t yet tested 2 digits times 3 digits.

This site uses Akismet to reduce spam. Learn how your comment data is processed.