Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Image: ubuntu2004
Packets of Buttons
The function has base cases which are the minimum number of packets to purchase for buttons where .
For a number of buttons , the vector is appended with the minimum value of the base cases after having subtracted the packet sizes from , incrementing the total number of packets by in each iteration with the condition that .
It then returns the final value of the vector .
The Greedy Method
Alternatively, a greedy algorithm does actually works for buttons although it will not work for all values of . The function calculates the minimum number of packets required to purchase for buttons with base cases:
The function returns a vector with the required number of each sized packet. The sum of this vector is the total minimum number of packets required to purchase to have buttons.