Your mission
In programming, it is very common to solve two complementary problems with division: distributing without exceeding available items (integer division rounded down) and storing without leaving anything out (division rounded up). Additionally, the modulo operator (%) does not calculate percentages: it returns the remainder of an integer division.
Implement the solve(input) function, which receives a JSON object with three integer properties:
cantidadObjetos: integer between 0 and 100000.
cantidadPersonas: integer between 1 and 1000.
objetosPorCaja: integer between 1 and 1000.
You must solve two independent problems for the same cantidadObjetos:
- Equal distribution among people (without splitting individual items):
objetosPorPersona: how many whole items each person receives, calculated with Math.floor(cantidadObjetos / cantidadPersonas).
objetosSobrantes: how many items remain undistributed, calculated with cantidadObjetos % cantidadPersonas.
repartoExacto: boolean true only when objetosSobrantes === 0.
- Box packing (without exceeding the capacity of each box):
cajasCompletas: how many boxes are filled to their maximum capacity, calculated with Math.floor(cantidadObjetos / objetosPorCaja).
objetosUltimaCaja: how many items go into the partial box (cantidadObjetos % objetosPorCaja; 0 if no partial box exists).
cajasNecesarias: how many boxes are needed in total to store all items, calculated with Math.ceil(cantidadObjetos / objetosPorCaja).
Return a JSON object with those exact six properties: objetosPorPersona, objetosSobrantes, repartoExacto, cajasCompletas, objetosUltimaCaja, and cajasNecesarias.
Rules and constraints
- Do not use
if, else, switch, the ternary operator (? :), loops, arrays, classes, or helper functions.
- The divisors (
cantidadPersonas and objetosPorCaja) are always greater than zero.
- Do not round up items per person, and do not add unnecessary boxes when division is exact.