Advanced 4
Hello! This is page 16 of the course called “Y Combinator for Non-programmers”. If you just got here, click here to read from the beginning.

Y Combinator for
Non-programmers

Advanced 5: Additions, Multiplications, and Factorials

Slide 1 / 16

This is the final advanced level!

This is the final page for the advanced levels. You’re almost done.

You’re almost done

Looking for some other page?

Advanced 4·
·Epilogue
Slide 2 / 16

We won!

As promised, I will return the “Repeat” feature to you.

I will return
the “Repeat” feature to you

Yes! We’ve got all the features back. We won!

We’ve got all the features back!

Finally, we can use mathboxes to do additions and subtractions.

Calculates
Calculates

But guys… Do you really think it’s over now?

Hmm…?

Well, we are not done yet!

I still have an important thing I haven’t told you about. Let’s talk about it now.

What? You still have something to say?

Slide 3 / 16

What does this lunchbox do?

First, take a look at this lunchbox:

2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
24
3
34
1
12

Hmm… what is this?

It looks like you can fill each of and with a number…

Yeah. Try filling each of and with a random number.

Ok. Let’s use:

  • for
  • for
Fill each of and
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
24
3
34
1
12
With and
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
24
3
34
1
12

Now, let’s use this lunchbox that can be converted to

’s with on the bottom-right
→ Can be converted to
12
2
1

And this lunchbox that can be converted to :

’s with on the bottom-right
→ Can be converted to
123
3
2
1
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
24
3
34
1
12
Use lunchboxes that can be converted to
and
2
12
2
1
1
123
3
2
1
12
24
3
34
1
12

Ok, let’s see what happens when you run it.

Slide 4 / 16

If you run it…

Let’s run it.

  • It’s complicated, so you don’t need to follow all the steps. Save your eyes!
  • If you can’t wait, press Skip to the end →”.
2
12
2
1
1
123
3
2
1
12
24
3
34
1
12

It became this lunchbox that can be converted to .

’s with on the bottom-right
→ Can be converted to
12345
5
4
3
2
1
Slide 5 / 16

It can do addition

Now: What numbers did you use for and ?

I used and , and the final result was

If we used and
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
24
3
34
1
12
The final result was
Lunchbox that can be converted to

Does that mean: It calculated ?

It can do addition?

Exactly! Using the above lunchbox,

  • If you fill each of and with some number…
  • It calculates .
If you fill each of and
with some number and run it…
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
24
3
34
1
12
It will become a lunchbox that can be
converted to
Lunchbox that can be converted to

So: The above lunchbox can do addition of two numbers.

It can add two numbers

Oh wow…!

We thought we had to use the “Repeat” feature to calculate additions like this:

Calculates
2
1
1234
4
3
2
1
12
1
12
2
1
1
12
2
1

But it looks like we can do addition of two numbers without using the “Repeat” feature .

Exactly!

Slide 6 / 16

Another lunchbox

Next, how about this lunchbox? What do you think this lunchbox can do?

What can this lunchbox do?
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
12
2
1

It’s similar to the previous lunchbox but slightly different.

Let’s fill and with and like the last time, and see what happens.

Use for and for
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
12
2
1
Use lunchboxes that can be converted to
and
2
12
2
1
1
123
3
2
1
12
12
2
1

Ok, let’s run it.

This one takes time, so if you can’t wait, press Skip to the end →”.

2
12
2
1
1
123
3
2
1
12
12
2
1

It became a lunchbox that can be converted to .

’s with on the bottom-right
→ Can be converted to
123456
6
5
4
3
2
1
Slide 7 / 16

It can do multiplication

We started out with for and for

And the result was .

We started out with and
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
12
2
1
And the result was
Lunchbox that can be converted to

Maybe: It can do multiplication?

It can do multiplication?

Exactly! Using the above lunchbox,

  • If you fill each of and with some number…
  • It calculates .
If you fill each of and
with some number and run it…
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
12
2
1
It will become a lunchbox that can be
converted to
Lunchbox that can be converted to

So, it’s a lunchbox that can calculate multiplications.

It can calculate multiplications
Slide 8 / 16

It can do other calculations

By the way, we don’t have time to explain this, but lunchboxes can also do subtractions and divisions of two numbers.

So: Lunchboxes can do addition, multiplication, subtraction, and division.

Lunchboxes can do addition, multiplication,
subtraction, and division
Slide 9 / 16

Next up: The final topic!

What’s coming up next is the final topic we’ll cover. You’re so close to the finish.

You’re so close to the finish
Slide 10 / 16

Factorials

Furthermore, lunchboxes can do even more complicated calculations.

Like what?

For example: Lunchboxes can calculate factorials.

Factorials? What’s that?

The factorial of a number can be calculated as follows:

  • Start with a number, say , and…
  • Keep multiplying it with smaller numbers (each number is 1 less than the previous number)…
  • Until you reach .
Factorial:
Start with a number and keep multiplying
with smaller numbers until you reach .

Hmm… Can you give me an example?

For example: This is the factorial of . If you do the math, the result will be .

The factorial of .
If you do the math, the result will be .

Another example: This is the factorial of . If you do the math, the result will be .

The factorial of .
If you do the math, the result will be .

Ok, I think I got it…

Now, I will show you that: Lunchboxes can calculate factorials.

Slide 11 / 16

A simpler notation for multiplication

To calculate factorials, we need to use the lunchbox that can do multiplication (which we saw earlier).

But this time: Instead of using the actual lunchbox, we’ll use the following notation (abbreviation):

Instead of the actual lunchbox…
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
12
2
1
We’ll use this notation (abbreviation)
1
1

In this notation, the icon in the middle indicates multiplication.

The icon indicates multiplication

Hmm… ok, but why do we need to use this notation instead of the original lunchbox?

It’s because: The lunchbox that calculates factorials is going to be very complicated.

Therefore: We need to use this simpler notation to describe multiplications in order to save some space. Otherwise, the lunchbox will be too big.

We’ll use this notation to
save some space

I see…

Before we move on, let’s take a look at an example that uses this simpler notation.

For example: This is the earlier lunchbox that calculates :

A lunchbox that calculates
2
Lunchbox that can be converted to
1
Lunchbox that can be converted to
12
12
2
1

If we use the