Intermediate 2
Hello! This is page 9 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

Intermediate 3: Super Saya

Slide 1 / 13

The challenge

The villagers in Lambda Village were struggling with this difficult problem:

Challenge:
Fill each icon in such a way that,
1
1
13
2
23
1
After you run it,
the resulting lunchbox can be converted to .
Lunchbox that can be converted to

Hmm… I have no idea.

But we need to solve this to get our mathboxes back.

Looking for some other page?

Intermediate 2·
·Intermediate 4
Slide 2 / 13

Saya to the rescue

That’s when Saya , a little girl who lives in Lambda Village, appeared.

Saya,
a little girl who lives in Lambda Village

Hey guys! What are you doing there?

Hi Saya. Well, we have some bad news. The devil has taken our mathboxes .

To get them back, we need to solve this difficult question. But it’s too hard for us.

I see. I’ll help you then!

We appreciate it, but this isn’t for kids.

We tried hard but couldn’t solve it. I don’t think you can do it.

Slide 3 / 13

Saya’s Lunchbox

Saya spent some time thinking, and came up with the following lunchbox:

Hey, I filled each icon as follows. Can you take a look?

I filled each icon…
1
1
13
2
23
1
…as follows!
1
1
13
2
23
1

Hmm… I don’t think it’s going to work, but we’ll try anyway.

We’ll run this, and see if the result is a lunchbox that can be converted to .

We’ll run this lunchbox, and…
1
1
13
2
23
1
If it becomes a lunchbox that can be
converted to , success.
Otherwise, failure
Slide 4 / 13

What happens if you run it?

Let’s run it!

First: Because there are multiple pairs of 1’s, we start from the leftmost pair.

Press Run . (Or press to step through manually.)

If there are multiple pairs of 1’s,
start with the leftmost pair.
1
1
13
2
23
1

Second: We can’t start with the leftmost pair of 1’s because there’s only one item on the bottom (a sandwich ).

Therefore, we do the pair of 2’s.

Press Run :

If you can’t start with 1’s because
there’s only one item on the bottom row,
start with the pair of 2’s.
13
2
23
1

Third: We’ll need to start with the pair of 2’s again, just like the last time.

Press Run :

If you can’t start with 1’s because
there’s only one item on the bottom row,
start with the pair of 2’s.
12
2
1

So this is the final result.

Final Result
1
1

Oh…! This is…

The resulting lunchbox can be converted to .

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

So, it’s a success!

Yay!

No way! Can’t believe Saya solved it so easily!

Slide 5 / 13

Let’s dive in a little deeper

Surprise: Saya just solved the devil’s difficult problem.

Saya solved the devil’s problem

Wow, Saya, you’re awesome. Thank you for solving it!

Sure thing!

Thanks to Saya, we’ll get our mathboxes back!

Yes, but: Before we move on, let’s dive in a little deeper.

We’ll spend a bit of time to talk about some important stuff.

Hmm… ok, let me hear what you have to say.

First: Here’s what we’ve learned so far. Here’s a lunchbox that can be converted to :

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

If we combine it with Saya’s lunchbox, it will become a lunchbox that can be converted to .

If we combined it with
Saya’s lunchbox…
1
1
13
2
23
1
It will become a lunchbox
that can be converted to
Lunchbox that can be converted to

So, by using Saya’s lunchbox,

  • A lunchbox that can be converted to
  • Becomes a lunchbox that can be converted to .
A lunchbox that can be converted to
becomes one can be converted to
Slide 6 / 13

What if we combined it with ?

Now, here’s a question: Suppose that we combine Saya’s lunchbox with a lunchbox that can be converted to .

What do you think happens when you run it?

Combine Saya’s lunchbox with
a lunchbox that can be converted to
1
Lunchbox that can be converted to
1
13
2
23
1
What happens when you run it?

Hmm… I have no idea…

Last time, became . Don’t know what will happen this time…

Last time, became
What about this time?
What will become?

Let’s check!

Slide 7 / 13

What will become?

This time, we’ll use this lunchbox that can be converted to .

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

Let’s combine it with Saya’s lunchbox.

Combine with Saya’s lunchbox
1
1
1
1
13
2
23
1

Let’s run it. This time, we’ll continue running until the end without stopping.

You can also skip to the end.

1
1
1
1
13
2
23
1

The resulting lunchbox can be converted to .

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

That means…

  • A lunchbox that can be converted to
  • Became a lunchbox that can be converted to ?
Combine Saya’s lunchbox with
a lunchbox that can be converted to
1
Lunchbox that can be converted to
1
13
2
23
1
If we run it,
it becomes a lunchbox
that can be converted to
Lunchbox that can be converted to

That means: By using Saya’s lunchbox, became .

became
Slide 8 / 13

It can add

So, by using Saya’s lunchbox:

  • becomes , and…
  • becomes .
becomes , and
becomes

Do you see the pattern?

Maybe…it can add ?

Exactly!

  • If you combine Saya’s lunchbox…
  • …with a lunchbox that can be converted to ,
  • After running it, it becomes a lunchbox that can be converted to .
Combine Saya’s lunchbox
with a lunchbox that can be converted to
1
Lunchbox that can be converted to
1
13
2
23
1
If you run it,
it becomes a lunchobox
that can be converted to
Lunchbox that can be converted to

In other words: becomes .

That’s why “it can add .”

becomes
Slide 9 / 13

It can “reproduce” the “Plus 1” feature

Now, let’s recall that: Mathboxes have the “Plus 1” feature .

Using a mathbox, you can use the “Plus 1” feature to add to any number.

Using a mathbox, you can use
the “Plus 1” feature
…to add one to a number.

And on this page, we learned that: You can also add to a number using a lunchbox .

You can add to a number
using a lunchbox

Here’s how: Instead of , by using Saya’s lunchbox, you can add to a number.

Combine Saya’s lunchbox
with a lunchbox that can be converted to
1
Lunchbox that can be converted to
1
13
2
23
1
If you run it,
it becomes a lunchobox
that can be converted to
Lunchbox that can be converted to

Therefore: A mathbox that uses the “Plus 1” feature can be “reproduced” using a lunchbox.

A mathbox that uses the “Plus 1” feature
can be “reproduced” using a lunchbox

So, to add 1 to a number:

  • In a mathbox, we use , and…
  • In a lunchbox, we use Saya’s lunchbox.
In a mathbox, we use
In a lunchbox, we use
Saya’s lunchbox to reproduce
the “Plus 1” feature .
1
Lunchbox that can be converted to
1
13
2
23
1
Slide 10 / 13

You can reproduce more complicated mathboxes

Of course, you can also reproduce more complicated mathboxes.

For example, take a look at this mathbox that appeared on Beginner 1. If you run it, the result will be .

Can you figure out how to reproduce this using a lunchbox?

I got it!

First, we’ll use this lunchbox that can be converted to :

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

Then, use my lunchbox twice:

Use my lunchbox twice to reproduce
12
12
2
1
2
13
2
23
1
1
13
2
23
1

Correct! Let’s run it to check.

(To save time, we’ll skip right to the end when you run it.)

12
12
2
1
2
13
2
23
1
1
13
2
23
1

The resulting lunchbox can be converted to .

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

Therefore, we were able to reproduce the earlier mathbox.

This mathbox can be reproduced…

…using this lunchbox
12
Lunchbox that can be converted to
2
13
2
23
1
1
13
2
23