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.

# .css-1nqcc75{color:#ec407a;}Advanced 3:Replace Parts of a Lunchbox

Slide 1 / 12

### Things will get 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?

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?

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.