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