Advanced 3
Hello! This is page 15 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 4: Y Combinator

Slide 1 / 13

The most complicated lunchbox ever

In this page, I’ll show you the most complicated lunchbox ever.

The most complicated lunchbox ever

It will be hard, but you don’t need to understand everything. Even if you don’t fully get it, you should keep reading.

Looking for some other page?

Advanced 3·
·Advanced 5
Slide 2 / 13

On the previous page…

On the previous page, Saya came up with a lunchbox that might be able to reproduce the “Repeat” feature .

Can we reproduce this lunchbox that uses
the “Repeat” feature
…with this lunchbox?
2
1
1234
4
3
2
1
12
1
12
2
1
1
12
2
1

According to Saya, the above lunchbox will repeat three times, just like when using the “Repeat” feature .

If you run this lunchbox…
2
1
1234
4
3
2
1
12
1
12
2
1
1
12
2
1
Just like the “Repeat” feature ,
it repeats three times on
123
3
2
1
And calculates

Let’s see if this is actually true.

Slide 3 / 13

What steps does it go through?

On this page, we’ll run the lunchbox that I came up with, and see what steps it goes through.

When we run this…
2
1
1234
4
3
2
1
12
1
12
2
1
1
12
2
1
What steps does it go through…
…before it becomes the same as
the “Repeat” feature ?
123
3
2
1

Yeah, we need to see what happens in between the beginning and the end.

Slide 4 / 13

Let’s run it!

Ok, let’s do it.

  • We’ll pause several times in between for explanation.
  • You don’t have to follow all the steps with your eyes. Just glance over it. Save your eyes!
  • If you can’t wait, press Skip to the next stopping point →”.

Press Run !

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

It’s so complicated…

It’s not too bad if you look carefully.

Take a look at this yellow section in the middle.

Take a look at this yellow section
in the middle
1245
5
3
12
2
1
1234
4
3
2
1
34
12
2
1
1234
4
3
2
1
2
1

Let’s ignore this section for now. We don’t need to worry about it until later.

We’ll replace it with the “Ignore for Now” sign:

Ignore the yellow section for now
1234
4
Ignore
for Now
3
2
1

It’s much simpler now.

Now, let’s take a look at the bottom section of the “Conditional” feature :

Because is , which is NOT zero, it chooses .

Check if is
1234
4
Ignore
for Now
3
2
1
Because is NOT , it chooses
1234
4
Ignore
for Now
3
2
1
123
3
Ignore
for Now
2
1
Slide 5 / 13

The second time

We’ll now un-ignore the section we ignored earlier:

Un-ignore the section we ignored earlier
123
3
Ignore
for Now
2
1
134
4
2
12
2
1
1234
4
3
2
1
23
12
2
1
1234
4
3
2
1
1

Let’s continue. Press Run !

134
4
2
12
2
1
1234
4
3
2
1
23
12
2
1
1234
4
3
2
1
1

Oh! This yellow section is exactly the same as the one we ignored last time.

This yellow section is exactly the same
as the last time
123567
7
6
4
12
2
1
1234
4
3
2
1
45
12
2
1
1234
4
3
2
1
3
2
1

Yes: This yellow section has appeared again.

Hmm… interesting.

Let’s ignore this section again:

Let’s ignore the yellow section again
123456
6
5
Ignore
for Now
4
3
2
1

I’ve highlighted the differences from the last time in yellow below. Take a look.

Last time
1234
4
Ignore
for Now
3
2
1
This time
123456
6
5
Ignore
for Now
4
3
2
1

Pay attention to these two differences in particular:

  • was before, but it’s now .
  • There’s now a icon on the bottom.

I see, the number in went from to .

So it decreased by one.

The number in decreased by one

Maybe: If we continue, maybe the number in will become next?

Let’s see if that turns out to be true.

Slide 6 / 13

The third time

Let’s continue. We’ll un-ignore the section we ignored earlier.

Un-ignore the section we ignored earlier
123456
6
5
Ignore
for Now
4
3
2
1
123567
7
6
4
12
2
1
1234
4
3
2
1
45
12
2
1
1234
4
3
2
1
3
2
1

Press Run !

123567
7
6
4
12
2
1
1234
4
3
2
1
45
12
2
1
1234
4
3
2
1
3
2
1

Again: The middle section is exactly the same as before. So we’ll ignore this again:

This yellow section is exactly the same
as the last time…
12346789
9
8
7
5
12
2
1
1234
4
3
2
1
56
12
2
1
1234
4
3
2
1
4
3
2
1
So let’s ignore it for now
12345678
8
7
6
Ignore
for Now
5
4