Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:32:04+00:00 2026-05-25T09:32:04+00:00

Yesterday while trying to fall asleep I started thinking about how to solve the

  • 0

Yesterday while trying to fall asleep I started thinking about how to solve the problem below and realized I couldn’t come up with a good algorithm. This is not a school assignment even if it might look like one, I just want to find an answer. 🙂

Basically let’s imagine a work schedule for employees in a store. The program should generate schedule suggestions based on a set of requirements.

The requirements are:

  • Only one employee works any given week.
  • An employee can’t work two weeks in a row.
  • There should be a way to prevent an employee from getting
    scheduled to work a certain week (vacation).
  • The distribution should be as even as possible, i.e. if we have
    employees A, B and C they should get approximately the same ammount
    of weeks off and those weeks should be as evenly distributed as
    possible.

What would be the best way to attack this problem? Perhaps functional programming is better for solving this?

EDIT: Now I know this type of problems is called “resource constrained scheduling”. Is a bit hard to goole for this as “scheduling” often refers to things like scheduled tasks or threading. For the people who still think I’m asking for homework solutions (despite me explicitly claiming otherwise above), you can check out my previous questions, I think they clearly indicate I’m not a student…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:32:05+00:00Added an answer on May 25, 2026 at 9:32 am

    Even though it seems as if this is homework, I prefer to believe you.

    Here is what I’ve come up with:

    let rec assignWork n upTo last workers =
        if n <= upTo then
            let checkNameIsEqualToLast =
                match last with
                | Some n -> ((=) n)
                | _ -> fun _ -> false
            let (name, _, _) as worker =
                workers
                |> List.filter (not << fun (name, _, v) -> checkNameIsEqualToLast name || List.exists ((=) n) v)
                |> List.sortBy (fun (_, w, _) -> w)
                |> List.head
            workers
            |> List.map (function
                | n, w, v when n = name -> n, w + 1, v
                | w -> w)
            |> assignWork (n + 1) upTo (Some name)
            |> fun t -> name::t
        else []
    

    For example:

    let workers =
        List.zip
            [ 'A' .. 'E' ]
            [
                []
                [ 2 .. 4 ]
                [ 3 .. 5 ]
                [ 1 .. 10000 ]
                [ 3 ]
            ]
        |> List.map (fun (c, v) -> c, 0, v)
    
    assignWork 1 16 None workers
    

    The output is (seems reasonable to me):

    val it : char list =
      ['A'; 'C'; 'A'; 'E'; 'B'; 'C'; 'B'; 'E'; 'A'; 'B'; 'C'; 'E'; 'A'; 'B'; 'C'; 'E']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I moved CultureRater.com across to XHTML 1.0 Transitional and while the javascript below
I am fairly new to using infragistics controls (started yesterday). While they are (very)
The whole day yesterday I've been trying to solve this but it's proven to
I'm very new to python (just started yesterday), and I'm trying to create permutations
I have installed Nuget 1.2 yesterday, and today, while I was trying to install
While looking at a micro-optimization question that I asked yesterday ( here ), I
Yesterday, I have a discussion with my colleagues about HTTP. It is asked why
I am looking since yesterday to fix this problem, I know there are plenty
Im developing my app and yesterday while I was playing with it crashed. I
I ran into an error yesterday and, while it's easy to get around, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.