Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
Algorithm to fit people in a monthly calendar

I have an interesting algorithm to build and I have tried a couple of things but couldn't get it just right.

I have the following set of rules:

  • 16 people to fill every day of the month (let's call it 28 days to make it even weeks)
  • 4 people per day
  • Each person should have a maximum of 7 days a month
  • There has to be two days between each picked day (so if Person1 has a Monday, they shouldn't have another shift on Saturday-Sunday before nor Tuesday-Wednesday after)
  • Each person should have a free weekend during the month (we include Fridays during weekends, so no shifts on Fri-Sat-Sun once)

What I've tried so far (there's not a lot of svelte-specific code, mostly js):

https://svelte.dev/repl/0fc5a8e1b2a241a9985950c6a0a1ec43?version=3.44.3

https://svelte.dev/repl/c66a7de71cda46ec94fc1e11811a6883?version=3.44.3

They are similar approaches, where the first one goes over each day in the range and tries to pick people one day at a time and the second one goes over people and tries to pick all of that person's days at once.

My issue with both of those approaches is that usually there will be days where not all people are selected.

Is there a way to improve the algorithm? Do I have another way to go about this?

Any help will be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!