Last active
August 29, 2015 14:22
-
-
Save mzdravkov/d0301e1406270d11d6ea to your computer and use it in GitHub Desktop.
schedule problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# our schedule is 3D array with (5 workdays, 8 workhours, 4 positions) for dimensions | |
schedule = Array(Int, 5, 8, 4) | |
day = hour = position = 0 | |
while true | |
schedule = Array(Int, 5, 8, 4) | |
remaining_hours = fill(20, 8) | |
bad_schedule = false | |
for day = 1:5, hour = 1:8, position = 1:4 | |
intern = rand(1:8) | |
tried = Array(Int, 8) | |
# if the intern has no more hours or if he is working at another position at the same time | |
while remaining_hours[intern] == 0 || findfirst(schedule[day, hour, :], intern) != 0 | |
intern = rand(1:8) | |
tried[intern] = 1 | |
# if we have tried all interns and no one is able to work at that time | |
if findfirst(tried, 0) == 0 | |
bad_schedule = true | |
break | |
end | |
end | |
if bad_schedule | |
break | |
end | |
schedule[day, hour, position] = intern | |
remaining_hours[intern] -= 1 | |
end | |
if !bad_schedule | |
break | |
end | |
end | |
println(schedule) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment