5 kyu

Department scheduler [simple]

87 of 150MMMAAANNN

Description:

You are the Head of the Department and your responsibilities include creating monthly schedules for your employees.

Your employees work in shifts. Each shift is 24 hours. Employment policy prohibits employee from working more than 24 hours in a row, so one employee cannot have two consecutive shifts.

There must be n people at work each day. Arrange employees over the schedule so that their workload is equal or differs from others minimally (i. e. difference between any two employees must not exceed one shift).

If it is not possible to ensure one employee does not work two days in a row due to insufficient staff, return None/null/nil.

Arguments

  • Array of employee names as strings. Example: ["Smith", "Jones", "Gonzalez", "White", "Jackon", "Taylor"].
  • Month and year in "MMYYYY" format.
  • n, the number of employees per shift.

Output

  • Array of arrays, each representing a day in the given month. Each day array should contain exactly n employee names, representing the employees scheduled for that day.
  • Or None/null/nil, if it is impossible to create a valid schedule.

#Example

Employees Array: ["Smith", "Jones", "Gonzalez", "White", "Jackon", "Taylor"]
Month and year: "022015"
Number of employees per shift: 3

may return

   [["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"],
    ["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"],
    ["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"],
    ["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"],
    ["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"],
    ["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"],
    ["Smith", "Jones", "Gonzalez"],
    ["White", "Jackson", "Taylor"],
    ["Jones", "Smith", "Gonzalez"],
    ["Taylor", "White", "Jackson"]]

Here each employee has 14 shifts and no one has two consecutive shifts.

Note: rules for leap years do apply, so keep that in mind ;)

Scheduling
Algorithms

Stats:

CreatedMay 17, 2015
PublishedMay 17, 2015
Warriors Trained491
Total Skips152
Total Code Submissions1251
Total Times Completed150
Python Completions87
JavaScript Completions48
CoffeeScript Completions8
Ruby Completions31
Total Stars28
% of votes with a positive feedback rating96% of 56
Total "Very Satisfied" Votes53
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments16
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • MMMAAANNN Avatar
  • GiacomoSorbi Avatar
  • Just4FunCoder Avatar
Ad