Skip to content

Instantly share code, notes, and snippets.

@spiritinlife
Created June 22, 2021 16:15
Show Gist options
  • Save spiritinlife/8c19b5fe9a57390804394e824ddf6b7e to your computer and use it in GitHub Desktop.
Save spiritinlife/8c19b5fe9a57390804394e824ddf6b7e to your computer and use it in GitHub Desktop.
random
requestedProducts = […..]; # input array of products we have to make
For next shift:
nextShiftProducts = []; # keeps track of current shift products
# as long as the sum of this shift products are less than 8 we can try to add another product
while sum(nextShiftProducts hours) < 8: 

for every requestedProducts:
if product.hours + sum(nextShiftProducts hours) < 8: # if we can add this product
add product to nextShiftProducts
remove product from requestedProducts
continue; # try to fill again remaining hours with another product
break; # if we are here then none of the products could be used for this shift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment