## Teaser 2960: Bags of sweets!

**From The Sunday Times, 16th June 2019** [link]

I recently bought a number of equally priced bags of sweets for a bargain price, spending more than 50p in total. If they had been priced at 9p less per bag, I could have had 2 bags more for the same sum of money. In addition, if each had cost 12p less than I paid, then I could also have had an exact number of bags for the same sum of money.

How much did I spend in total on the sweets?

[teaser2960]

## Jim Randell 11:47 pm

on14 June 2019 Permalink |If we buy

nbags of sweets atxpence per bag, then the total outlayn.xcan be expressed as:(for some whole number

k, wheren > 1).From which we see:

This Python program finds the first value of

nthat satisfies the conditions and gives an integer value fork.Run:[ @repl.it ]Solution:The total spend was 216p.With a bit more analysis we can show this is the only solution.

We can write an expression for

kas:And this only gives a whole number when

16 / (9n – 6)has a fractional part of 1/3.This is only possible for

n = 1, 2, 6.n = 1givesx = 13.5p, n.x = 13.5p, which is not more than 50p (and we wantn > 1anyway).n = 2givesx = 18p, n.x = 36p, which is not more than 50p.n = 6givesx = 36p, n.x = 216p, so this is the solution.Here is a program that uses this analysis to consider all possible solutions, by looking at the divisors of 48:

Removing the check at line 14 will give all three solutions for the equations.

LikeLike

## GeoffR 6:49 pm

on16 June 2019 Permalink |We can put Jim’s initial three equations into a MinZinc constraint for an easy solution

LikeLike

## Jim Randell 8:46 am

on17 June 2019 Permalink |@GeoffR: This approach works OK for cases where the price per bag is a whole number (which is the case in the actual solution).

I didn’t assume that and found there were 3 candidate solutions that satisfied the 2 equations, one of which has the bags priced with a fractional amount. Two of the candidates are eliminated by the inequality (including the one where the bags are priced a fractional amount), leaving a single solution.

LikeLike

## GeoffR 3:12 pm

on17 June 2019 Permalink |@Jim: I can see you are making a mathematical point about prices for fractional amounts, but is this applicable for this teaser ?

We don’t have fractional pennies these days in our monetary system, so maybe we should assume that prices per bag are in whole numbers of pennies ?

LikeLike

## Jim Randell 4:56 pm

on18 June 2019 Permalink |@GeoffR: It was just a comment to try and extract a bit more interest from a relatively straightforward puzzle.

I try not to make additional assumptions about the puzzle if I can help it. From the formula for

xwe see that the price per pack is a whole number of half-pennies, so it seemed reasonable to allow this. And we do get an extra potential solution if we do. Although this solution is then removed by the “more than 50p” requirement, so it doesn’t really matter if we consider it or not.LikeLike