Answer the question
In order to leave comments, you need to log in
Graphing algorithm?
Hello
There is a task to build an appointment
schedule, there is a schedule, divided into 30 minutes,
i.e. 9.00 9.30 10.00 and so on
there are 3 doctors (there can be as many as you like),
each doctor can be both busy and free at each interval
, the appointment takes 1 hour.
those. if one of the doctors is free at 9.00 and 10.00 and 9.30 is busy, then we cannot sign up for 9.00
, as a result, we must get a grid of time with each of the cells active or not.
those. for example, if 9.00 is active, then we mean that there is at least 1 doctor to whom you can make an appointment at 9.00 and he will be able to take 1 hour. (Free intervals are 9:00 and 9:30)
(i.e., in fact, it may turn out that, for example, at 9, everyone has free time, and at 9.30, the cell at 9.00 is busy, respectively)
I understand that this cannot be solved without any algorithm.
Unless it's a brute force for all options in all ways, which, it seems to me, is not effective
Answer the question
In order to leave comments, you need to log in
not an algorithm, but in javascript I would do something like this
doc1 = [850, 950, 1100] // для удобства счета 800 = 8:00 850 = 8:30 итд
doc2 = [1100, 1200]
doc3 = [1000]
docs = [doc1, doc2, doc3]
STEP = 50 // 0.5 часа
for (let i = 800; i < 1400; i += STEP){
console.log(i)
const found = docs.filter(d => !d.some(time => [i - STEP, i, i + STEP].includes(time)))
console.log(found) // выводит доступных врачей на время i, или пустой массив, если никого нет
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question