top of page
Bags and sweets
Solution
The simplest is to put one sweet in each bag and all the remaining sweets in the first bag.
​
You may come up with an algorithm to distribute the sweets more evenly – but is that a “better” solution?
​
​
b = INPUT “number of bags”
s = INPUT “number of sweets”
IF b is even AND s is odd THEN
OUTPUT “Not possible”
ELSE IF b is odd AND s is even THEN
OUTPUT “Not possible”
ELSE
put one sweet in each bag
put remainder in first bag
ENDIF
try me...
bottom of page