I'm trying to solve an algorithm problem, like google calendar.
I have a series of events with start_hour and end_hour and some intersect.
For those that intersect, they must be placed in parallel.
We have this:
$events=[
'1'=>['start_hour'=>'10:00','end_hour'=>'12:00'],
'2'=>['start_hour'=>'13:00','end_hour'=>'14:00'],
'3'=>['start_hour'=>'14:00','end_hour'=>'15:00'],
'4'=>['start_hour'=>'17:00','end_hour'=>'20:00'],
'5'=>['start_hour'=>'18:00','end_hour'=>'19:00'],
'6'=>['start_hour'=>'19:00','end_hour'=>'21:00'],
'7'=>['start_hour'=>'19:00','end_hour'=>'21:00'],
'8'=>['start_hour'=>'21:00','end_hour'=>'23:00'],
];
Graphic should look like this:
10:00 [1][1][1][1]
11:00 [1][1][1][1]
12:00 [ ][ ][ ][ ]
13:00 [2][2][ ][ ]
14:00 [2][2][3][3]
15:00 [ ][ ][3][3]
16:00 [ ][ ][ ][ ]
17:00 [4][ ][ ][ ]
18:00 [4][5][ ][ ]
19:00 [4][5][6][7]
20:00 [4][ ][6][7]
21:00 [8][ ][6][7]
22:00 [8][ ][ ][ ]
23:00 [8][ ][ ][ ]
What I have tried:
I tried to build an array like this:
$result=[
'1'=>['collision_index'=>0,'collision_count'=>1],
'2'=>['collision_index'=>0,'collision_count'=>2],
'3'=>['collision_index'=>1,'collision_count'=>2],
'4'=>['collision_index'=>0,'collision_count'=>4],
'5'=>['collision_index'=>1,'collision_count'=>4],
'6'=>['collision_index'=>2,'collision_count'=>4],
'7'=>['collision_index'=>3,'collision_count'=>4],
'8'=>['collision_index'=>0,'collision_count'=>4],
]
But I can't put them in order and they overlap.