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
1
Lunchbox that can be converted to

Summary: A mathbox that uses the ā€œPlus 1ā€ feature can be ā€œreproducedā€ using a lunchbox. As long as you understood this, you don’t need to understand all the details.

A mathbox that uses the ā€œPlus 1ā€ feature
can be ā€œreproducedā€ using a lunchbox

Note: There are other lunchboxes that can reproduce the ā€œPlus 1ā€ feature . Saya’s lunchbox is not the only solution.

If you’re curious, press ā€œContinue readingā€ below. (It’s optional.)

Slide 11 / 13

Can we reproduce other mathboxes?

Remember that: In Beginner 1 and 2, we explained that mathboxes also have other features, which are:

  • The ā€œMinus 1ā€ feature , and
  • The ā€œRepeatā€ feature .
A mathbox that uses the ā€œMinus 1ā€ feature
A mathbox that uses the ā€œRepeatā€ feature
(Repeat four times)

Question: Can we also reproduce these features using lunchboxes?

Can we reproduce and
using lunchboxes?

You don’t need to answer this question now: We’ll talk about this soon.

Slide 12 / 13

Side Note: Too Hard?

Hey Minion, I want to tell you something…

Sure, what’s up?

The problem on the last page was too difficult! There’s no way we could’ve come up with an answer as quickly as Saya did.

Maybe computer science is too hard for us…?

The previous problem:
13
2
23
1

There’s no way we could’ve come up with
this answer as quickly as Saya did
13
2
23
1

Oh, don’t worry! The problem was very difficult. We didn’t expect you to answer it.

You don’t need to be able to answer questions like this to learn computer science.

Oh, really?

As long as you understand it after looking at the answer, you’ll be fine.

Ok… I feel much better now. Thank you, Minion!

No problem. Let’s get back to the story.

Slide 13 / 13

Back to the story…

The villagers are all very happy that the question is now solved.

Thanks to Saya, we solved the difficult question.

That means we’ll get our mathboxes back.

However: Saya doesn’t seem too happy.

Hey Minion, I noticed something very strange…

Oh really? What do you mean?

What strange things did Saya notice? Let’s take a look on the next page.

Go to Next PageContinue to Intermediate 4
2 more intermediate levels left!
Intermediate 2
Japanese Site (ę—„ęœ¬čŖžē‰ˆ) Ā· About this Site Ā· Twemoji