Gabriele Ferro Home

Dev Advent Calendar – Day #05

Yesterday Santa needed our help to improve his shipping algorithm, and today he wants us to write a function that generates random bags of sweets.

There are some restrictions that have to be respected though, because Santa Claus wants there to be no duplicate sweets in the bags and the bags should be different from each other as much as possible.

Here is my solution, I even made a drawing to better understand the steps of 'my' algorithm.

The idea is to create a zone containing one candy of each type. From this zone we will randomly select sweets, remove them from the zone and place them in a temporary bag. Once the desired amount of sweets has been entered, we will assign the bag a unique number and place it in a BIG bag. Finally we make sure that the temporary bag is empty and that the initial zone again contains one candy of each available type.


  1. Click the participation link
  2. Clone your repository
  3. Solve the puzzle
  4. Test your solution
  5. Add your Twitter handle
  6. Git push your changes

February 2024


Gabriele Ferro Home
Copyright © Ferro Gabriele. All rights reserved.