Advanced 2
Hello! This is page 14 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 3: Replace Parts of a Lunchbox

Slide 1 / 12

Things will get harder

Warning: From this page, things will get much harder.

Things will get harder!

You don’t need to understand everything immediately. Even if you don’t completely get it, please keep reading.

Looking for some other page?

Advanced 2·
·Advanced 4
Slide 2 / 12

A very complicated lunchbox

Let me give you a hint to reproduce the “Repeat” feature using a lunchbox.

Repeat
times
Reproduce with
a lunchbox
Repeat
times
Reproduce with
a lunchbox

Let’s take a look at this lunchbox:

A complicated lunchbox
1
123
3
2
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234

This looks really complicated…

Now, here’s a question: What happens when you run it?

Well… there’s no way I can figure it out in my head. It’s too complicated.

I figured it out! I think the result will be a lunchbox that can be converted to .

I think the result will be
a lunchbox that can be converted to
Lunchbox that can be converted to

Correct. Saya, You’re exactly right!

What? How is it possible that you figured it out so quickly?

Saya, did you solve it all in your head?

Not really. Actually, I used a trick. Let me explain.

Slide 3 / 12

Replace each section: Phase 1

First: Take a look at the top section.

Take a look at the top section
1
123
3
2
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234

Oh! The top section is actually a lunchbox that can be converted to .

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

Yes. So we’ll replace this section with .

Replace the top section with
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234

Second: Take a look at the middle-right section.

Take a look at the middle-right section
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234

The middle-right section is actually a lunchbox that can be converted to .

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

Yes. So we’ll replace this section with .

Replace the middle-right section with
1
1
45
5
13
2
23
1
3
2
1
1234

I see…

Slide 4 / 12

Replace each section: Phase 2

Now, take a look at this section.

Take a look at this section
1
1
45
5
13
2
23
1
3
2
1
1234

This looks like Saya’s lunchbox that can reproduce the “Plus 1” feature .

Saya’s lunchbox that can reproduce
the “Plus 1” feature
13
2
23
1

Exactly. So we’ll replace this with .

Replace with
1
1
45
5
3
2
1
1234

Hmm… it’s getting much simpler.

Slide 5 / 12

Replace each section: Phase 3

Finally, take a look at the bottom-right section.

Take a look at the bottom-right section
1
1
45
5
3
2
1
1234

Oh! This looks exactly like the one we saw on the last page: a lunchbox that reproduces the “Conditional” feature .

A lunchbox that reproduces
the “Conditional” feature
4
Lunchbox that can be converted to
3
Lunchbox that can be converted to
2
1
Lunchbox that can be converted to
1234

Exactly. So we’ll replace it with the “Conditional” feature .

Replace with the “Conditional” feature

Here’s how we’re going to replace it:

Before (the bottom right section)
45
5
3
2
1
1234
After (the bottom right section)
12
2
1

After the replacement, it’ll look like this:

After replacing with
the “Conditional” feature
1
1
12
2
1

Wow, it’s much simpler now!

Slide 6 / 12

Let’s run it

Let’s run it. Press Run !

1
1
12
2
1

From here, it’s simple.

  • Because is , which is not zero…
  • The result will be what’s in , which is .

Press Run !

12
2
1

See, the final result is .

The final result is

Hmm… You’re right.

Slide 7 / 12

What if we run it directly?

But… isn’t that cheating?

Saya’s method was to replace each section with the corresponding mathbox features…

Saya replaced each section…
1
123
3
2
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234
…with the corresponding mathbox features
1
1
12
2
1
And the result was

But I’m wondering: Would the result also be if we run the original lunchbox directly?

If we run
the original lunchbox directly…
1
123
3
2
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234
Would the result also be
?

Let’s check!

Slide 8 / 12

Run it directly

Let’s run the original lunchbox directly.

  • There are so many steps, so we’ll 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 end →”.
1
123
3
2
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234

The final result is a lunchbox that can be converted to .

’s with on the bottom-right
→ Can be converted to
1234
4
3
2
1

The result is the same as using Saya’s method.

So… I guess Saya’s method was right…?

Yes! Saya’s method was the correct approach.

Slide 9 / 12

What we learned so far

Let’s step back and review what we learned so far.

Saya solved the problem by replacing parts of a lunchbox with the corresponding mathbox features, like this:

Replacing parts of a lunchbox…
1
1
With the corresponding mathbox features
1
1

As we saw earlier: If you replace parts of a lunchbox with the corresponding mathbox features, the result will be the same.

If you replace parts of a lunchbox
with the corresponding mathbox features
The result will be the same.

And I encourage you to replace parts of a lunchbox as much as possible to make it simpler. (like Saya did)

This lunchbox is complex, so…
1
123
3
2
1
1
45
5
13
2
23
1
3
12
2
1
2
1
1234
Simplify it by replacing each section
with the corresponding mathbox feature
1
1
12
2
1
In either case,
the final result will be
Slide 10 / 12

How this is related to reproducing the “Repeat” feature ?

But I still don’t get it: How is this related to reproducing the “Repeat” feature using a lunchbox?

Repeat
times
Reproduce with
a lunchbox
Repeat
times
Reproduce with
a lunchbox

It looks like Saya noticed something:

Hey, I think I figured out how to reproduce the “Repeat” feature !

I think I figured out how to
reproduce the “Repeat” feature

Wow, really?

Yes, let me explain.

Slide 11 / 12

Repeat three times

First: Take a look at this mathbox with the “Repeat” feature .

A lunchbox with the “Repeat” feature

This mathbox repeats three times and calculates .

Repeats three times
123
3
2
1

I figured out how to reproduce this behavior using a lunchbox.

Really? Please show me how!

Slide 12 / 12

Add more stuff to the previous lunchbox

Here’s the lunchbox we used earlier on this page.

We’ll make some changes to this lunchbox to reproduce the “Repeat” feature .

The lunchbox we used earlier on this page
1
1
12
2
1

Here, I just added some items to this lunchbox. The yellow background indicates the added items.

The yellow background indicates the added items.
2
1
1234
4
3
2
1
12
1
12
2
1
1
12
2
1

Hmm… ok, what’s so special about this lunchbox?

It turns out that:

  • If you run the above lunchbox,
  • It behaves exactly like the earlier mathbox that has the “Repeat” feature .

Therefore, it becomes like this:

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

Wow, really?

If that’s true, that means we’ve reproduced the “Repeat” feature .

This mathbox with the “Repeat” feature
…can be reproduced by this lunchbox?
2
1
1234
4
3
2
1
12
1
12
2
1
1
12
2
1

But does it really work?

We need to run it to see if it’s correct.

Yes, let’s run on the next page to check.

Go to Next PageContinue to Advanced 4
2 more advanced levels left!
Advanced 2
Japanese Site (日本語版) · About this Site · Twemoji