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 notation to simplify the above lunchbox, it will look like below.

You can run it to calculate .

Using the notation
1
1

Ok. But how do we use this to calculate factorials?

Slide 12 / 16

Calculating factorials

Let me explain how to calculate factorials using a lunchbox.

First: Take a look at this lunchbox. Notice that there’s a sign between and .

There’s a sign between
and
2345
4
3
5
2
1
1

Next: We’ll add more items to the above lunchbox like this (sections in yellow background).

By the way, the bottom half is Y Combinator, which we used on the last page.

We add more items (yellow background).
The bottom half is Y Combinator
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1

That’s it! By using this lunchbox, you can calculate the factorial of any number.

Hmm… really?

Slide 13 / 16

The factorial of

Let’s use the above lunchbox to calculate the factorial of .

The factorial of :
The result will be .

To calculate this, we just need to change on the lunchbox to .

Change
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1
…to
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1

Let’s run it.

  • Because there are so many steps, we’ll skip some steps, and increase the playback speed to 3x.
  • While it’s running, we’ll dim the lunchbox so it’s easier for your eyes.
  • If you can’t wait, press Skip to the next stopping point →”.
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1

It’s not finished yet, but do you see what just happened?

It became .

Yes. So it does calculate the factorial of .

Let’s run until the end.

12
1
2

So: By running this lunchbox, it calculates the factorial of automatically.

If you put at the top
and run it…
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1
It becomes like this and automatically
calculates the factorial of
12
1
2
Slide 14 / 16

The factorial of

Before we finish this page: Let’s calculate the factorial of .

The factorial of :
The result will be

To calculate this, we just need to change on the earlier lunchbox to .

Change to
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1

Let’s run it.

2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1

It became .

See, it calculated the factorial of , right?

The factorial of ,
which is

I see. Very interesting!

Slide 15 / 16

Thanks to Y Combinator

So, by using this lunchbox, you can calculate the factorial of any number.

By using this lunchbox…
2
1
2345
4
3
5
2
1
1
12
1
12
2
1
1
12
2
1
You can calculate the factorial of any number.

It’s amazing!

This is possible because of Y Combinator, which is used in the bottom half of the above lunchbox.

  • By combining Y Combinator with a lunchbox that can calculate multiplications,
  • You can do complicated calculations like factorials.
By combining Y Combinator
1
12
2
1
1
12
2
1
…with a lunchbox that can
calculate multiplications…
You can do complicated calculations like factorials

I see. Y Combinator is indeed magical!

Y Combinator is magical!
Slide 16 / 16

Are there any calculations that lunchboxes cannot do?

What we learned here is that, lunchboxes can do complicated calculations. They’re more powerful than mathboxes.

Lunchboxes are more powerful
than mathboxes

Well, I have a question: Are there any calculations that lunchboxes cannot do?

That’s a very good question. Let’s talk about it on the next page.

The next page is the final page: Epilogue.

Finally… we’re almost done!

Go to Next PageContinue to Epilogue
Advanced 4
Japanese Site (日本語版) · About this Site · Twemoji