Why we add 5 specifically at 1:46?
I'm a bit confused on why we add 5 specifically. At 1:46, we added 5 to 16 slices making it 21 slices. How will this work in all cases, please? i.e. we can add 2 instead of 5 to the equation resulting in 18 slices and it would still give us the answer of 3 pizzas.
Because we are using floor division we need to ensure that the number is always higher than the number of pizzas needed, if say we needed 8 slices and we just added 2, the number would be 10 and when dividing it would still return 1 pizza, by adding 5 we ensure we always go above 12.
We don’t add 6 as that would be a whole other pizza, and if we actually had exactly the right number of people for whole pizzas, adding 5 would ensure we don’t order one pizza too many.
I am sorry but I am lost at (we don't order one pizza too many), please elaborate
I did not get the equation of adding 5 and dividing by 6. could you please elaborate
I think a possible explanation of the magic number 5 could be the following:
When you need 7 slices, 7 mod 6 = 1...1 extra slice, so will need to order 1 more pizza to cover this 1 extra slice.
When you need 8 slices, 8 mod 6 = 1...2 extra slice so will need to order 1 more pizza
When you need 9 slices, 9 mod 6 = 1...3 extra slices so will need to order 1 more pizza
When you need 10 slices, 10 mod 6 = 1...4 extra slices so will need to order 1 more pizza
When you need 11 slices, 11 mod 6 = 1...5 <<<Magic number 5, & 5 extra slices so will need to order 1 more pizza
When you need 12 slices, 12 mod 6 = 2...0
So the reminder of 6 will always be 1,2,3,4,5.
It means if we add this largest mod (number 5) to our total needed slices, it will ensure we order 1 more pizza to cover the extra slices.
So it will become:
7 slices +5 slices = 12 slices/6= 2 pizzas
8 slices +5 slices = 13 slices/6=2 Pizzas
11 slices+5 slices=16/6=2 pizzas
12 slices+5 slices = 17/6=2 pizzas
Or simply we can do it as follows i guess,
Since we want 16 slices, if we divide 16 slices with 6 slices then we get 2 pizzas which will be 12 slices and it is less than 16 slices , what we want is at least 16 slices , so instead of 2 pizzas if we have 3 pizzas, we get 18 slices in total, now it is greater than 16 and we can divide it by 4 slices to each of the 4 individuals and we get two remaining slices.
So with the idea that "//" is the floor division arithmetic function, or least integer function as some may call it. Is there a greatest integer function (or "ceiling division")??? If so, that would complement this specific situation much easier.
I found it a bit confusing when he wrote "Number of pizzas - A multiple of 6, or 1 higher than what we get from floor division."
I believe what he meant was that the numerator from number_of_pizzas, the one being divided by 6 using floor division, must either be:
1. A multiple of 6 (because each pizza has 6 slices)
2. One number higher than what is given from floor division (in this case we need [(4*4)//6] + 1)
To account for this, he adds 5 to total_slices because this considers both of the above factors. The number 5 is chosen because at most the number of slices needed is 5 off from being a multiple of 6, such as how if 13 slices are needed (13+5)//6 will give the required amount of pizzas.
Even if the sum exceeds the next multiple of six, floor division will still result in that multiple of six. For example, if 17 slices are needed, (17+5)//6 will still result with 3 pizzas even though 17+5 = 22 (this is more than the next multiple of 6, which is 18).