How to find easily between multiple agenda the “common” free time for all of them using Matrix and Hadamard operator

Mathematics is often viewed as complex but finally a lot of mathematical tools helps you in daily programming.

My problem of today is i have multiple agenda and i need to find between them the “common” free(available) time. 

If i had a strict mathematical language i will tell you that we will use Hadamard Operator between n matrix representing my schedule of each ressource to produce the final matrix where i can find the free time between this.

I will have this if A and B are 2 matrix of same dimensions using Hadamard (1 don’t read it, nightmare)

hadamard product

I will look very intelligent but’s easy and my girl of 10 years old could understand this if it’s better explained (yes). 

This morning at breakfast, she did it. (yes).

Let’s start for this course of “how to do university math when you have 10 years old” to resolve this programming algorythm :

I need to book rooms for teaching purpose. I have multiple room and multiple teacher. Teacher and room have their own agenda (let’s suppose via a google agenda) and room have their own schedule too.

Ok let’s suppose for this article that we have one teacher and is the matrix A.

To simplify, we will take only Monday, Tuersday, Wednesday by line and 2 slots : AM and PM for column


We say that we will fill one intersection between day (Monday,Tuesday,Wednesday) and time slot (here AM,PM) with 1 if the ressources is available at this time and 0 if the ressource is not available at this time. For example if the teacher A is NOT available on Monday Morning (Monday, AM) then i put a 0, i put a 1 the afternoon because the ressource is available (Monday,PM)


For the Room, we will add only one room for blog post purpose, it’s the matrix B and for it we pick also random slot available for example for our purpose i will put the Monday Afternoon as available (1) etc..


At this point, we have finished !

We can have easily what is the common time between this 2 agendas, and we may add a lot of agenda and do exactly the same thing by…..multiplying them .

The result will be what we search : the “available time”.

We will use Hadamard Operator to do that (see later)

in our case, it will be simple to do it “viewing” the stuff but when you  have 30 teachers then 30 matrix and 10 rooms how you will find the right solutions ?

Then we finish…let’s call “C” the representation of the possible “common available time” between A and B.

We will multiply A and B using Hadamard Operator.

the Hadamard Operator is simple : the new matrix let’s call it C.

C has the same “dimension” of A and B. In our case : 3 dimensions in line (Monday, Tuesday, Wednesday) and 2 dimensions in column (AM,PM). It’s a matrix 3×2 or an array if you do some programmation.

To compute the result for C of Monday, AM we take the Monday,AM of A and we multiply it by the Monday,AM of B then

C “Monday,AM” = A “Monday,AM” * B “Monday,AM”  = 0*0 = 0

Then for C “Monday,AM” = 0 = not available in our case.

We do the samething for all others 6 variables :

C “Monday,PM” = A “Monday,PM” * B “Monday,PM” = 1*1 = 1 = Available.

The 0 is “absorbant” and it’s why we pick it because it’s what we need 


Then for our problem we found at that the Monday Afternoon (PM) is the time where Agenda of Teacher (A) and Agenda of the Room (B) have available time.

We simplified a lot for educationnal purpose but you can imagine that the matrix C gives you back also all the “available slots” with n ressources “on the fly”. Only the power of computation of your computer will limit you .

If we have 30 teachers and 10 rooms we juste multiply all of them….using the same algo in the order we want and with the selection we want.

After the code itself can be done in what you want : python, php, ruby, javascript….

But the matrix A,B,C are simple array at 2 dimensions (3×2) or (2×3)

We can add dimensions. In “my problem”, i divided each day in slot of 5 minutes for example….

I will publish soon code for this purpose…but linking this with API like Cronofy which can link all known agenda (Apple, Google etc..) you can a very efficient algo to manage this “time cross” between x ressources.

And the result of my girl, Sofia, 9 years old, is there…after some basics explanations, he tooks here around 15 minutes to do the problem by herself.