Intermediate 3
Hello! This is page 10 of the course called â€śY Combinator for Non-programmersâ€ť. If you just got here, click here to read from the beginning.

Slide 1 / 9

### Quick review

On the last page, we learned that, by using Sayaâ€™s lunchbox, we can reproduce the â€śPlus 1â€ť feature of a mathbox.

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

Thatâ€™s it for the quick review. Letâ€™s continue.

Looking for some other page?

Intermediate 3Â·
Â·Intermediate 5
Slide 2 / 9

### Sayaâ€™s question

Looks like Saya noticed something strange.

Hey guys, can you take a look at this?

First, this lunchbox can be converted to , right?

â€™s with on the bottom-right
â†’ Can be converted to
1
1

What do you think happens if I combined it with my lunchbox that reproduces the â€śPlus 1â€ť feature ?

If I combined it with my lunchbox that
reproduces the â€śPlus 1â€ť feature â€¦
1
1
1
1
13
2
23
1
What happens
when you run it?

Well, because it calculates â€¦

It should become a lunchbox that can be converted to , right?

Should become a lunchbox
that can be converted to â€¦?

Letâ€™s run it to check.

Slide 3 / 9

### If you run itâ€¦

1
1
1
1
13
2
23
1

Unfortunately: I wonâ€™t be able to convert this lunchbox into a mathbox.

Canâ€™t convert this into a mathbox
12
2
1

Why not? Because it doesnâ€™t follow this pattern.

There needs to be one
on the top-right and some number of
â€™s on the bottom-right
One
Someâ€™s

There needs to be exactly one on the top-right, but there are two in this case.

There needs to be exactly one
on the top-right, but there are two.
Thatâ€™s why it cannot be converted to a mathbox.
12
2
1

Hmmâ€¦ whatâ€™s going on? Last time, it workedâ€¦

Slide 4 / 9

### If the same item exists in both.css-1gverla{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;color:white;line-height:1;width:1.5em;font-weight:bold;font-style:normal;height:1.5em;text-transform:uppercase;border-radius:100%;border-width:2px;border-style:solid;background-color:#7986cb;border-color:#3f51b5;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;font-size:0.85em;-webkit-transform:translateY(-0.05em);-ms-transform:translateY(-0.05em);transform:translateY(-0.05em);}t and.css-ltlwb2{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;color:white;line-height:1;width:1.5em;font-weight:bold;font-style:normal;height:1.5em;text-transform:uppercase;border-radius:100%;border-width:2px;border-style:solid;background-color:#66bb6a;border-color:#43a047;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;font-size:0.85em;-webkit-transform:translateY(-0.05em);-ms-transform:translateY(-0.05em);transform:translateY(-0.05em);}m, the results will differ

Let me tell you whatâ€™s going on.

First, letâ€™s label each item with t, l, m, or r.

Label items as t l m r
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

Notice that: The sandwiches are labeled as either t or m.

The sandwiches are labeled as
either t or m
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

Now, hereâ€™s the secret: If the same item exists in both t and m, then the result changes.

In this case, is in both t and m.

Thatâ€™s why it couldnâ€™t calculate .

tm
If the same item exists in both t and m,
then the result changes

Really? Why does that happen?

Let me use a simple example to explain.

Slide 5 / 9

### A Simple Example

Hereâ€™s a simple example that illustrates my point:

• The left lunchbox has different t and m.
• The right lunchbox has the same t and m (both ).

Letâ€™s see what happens to each lunchbox.

t and m
are different
2
1
t
l
12
m
r
2
1
t
l
12
m
r
2
1
t
l
12
m
r
2
1
t
l
12
The bottom two
are different
1
1
t and m
are the same
2
1
t
l
12
m
r
2
1
t
l
12
m
r
2
1
t
l
12
m
r
2
1
t
l
12
The bottom two
are the same
1
1

Weâ€™re not done yet, but did you notice something?

The bottom two are different on the left, but theyâ€™re the same on the right.

Yes. And if we continue until the endâ€¦

• On the left, the hamburger (which was r) will remain.
• On the right, the chicken (which was t) will remain.
1
t
l
1
r
1
t
l
1
1
t
l
1
r
1
t
l
1
r
1
t
l
1

So this is before and after:

Before:
t and m
are different
2
1
t
l
12
m
r
After:
Before:
t and m
are the same
2
1
t
l
12
m
r
After:

So, this illustrates that: If the same item exists in both t and m, then the result changes.

tm
If the same item exists in both t and mâ€¦
The result changes
Slide 6 / 9

### Back to the original example

Letâ€™s go back to the previous example that could NOT calculate .

This failed because was in both t and m, which caused the result to change.

Couldnâ€™t calculate
because was in both t and m,
which caused the result to change.
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

Hmmâ€¦ then what should we do in this case? Just give up?

Letâ€™s not give up. I think thereâ€™s a way.

Butâ€¦ what can we do?

Letâ€™s ask Minion if we can change the rule to fix this.

Special rule? What do you mean by that?

Iâ€™d like the following special rule to apply in cases like this:

• If the same item appears in both t and mâ€¦
• Change one of them to something different.
tm
Can we use this special rule?
If the same item appears in
both t and m,
change one of them to
something different

Sure, thatâ€™s fine.

Thank you!

Whatâ€¦ you can change the rule just like that?

Slide 7 / 9

### The Special Rule

Letâ€™s add the following special rule:

• If the same item appears in both t and mâ€¦
• It will automatically change conflicting tâ€™s to something different.
t
If the same item appears in
both t and m,
it will automatically change
conflicting t to something different.

So, if thereâ€™s the same item in both t and mâ€¦ (in this case: )

Warning: Same item in t m
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

Because of this special rule: The sandwiches in t will now become something else.

t
The sandwiches in t
will now become something else.

What does it become then?

It will turn into a random food item thatâ€™s not yet used.

In this case, it becomes fried potatoes .

tt
It turns into fried potatoes ,
a random food item
thatâ€™s not yet used.
Special rule:
Change t to something else
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

on the top became .

And t and m no longer overlap now.

Yes. Letâ€™s continue then. Press Run :

1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

Yay! It became a lunchbox that can be converted to .

â€™s with on the bottom-right
â†’ Can be converted to
12
2
1

That means it calculated successfully.

Yes. Letâ€™s summarize what we just did.

Slide 8 / 9

### Summary

What we learned: If you combine Sayaâ€™s lunchbox which reproduces the â€śPlus 1â€ť feature â€¦

Sayaâ€™s lunchbox which reproduces
the â€śPlus 1â€ť feature
13
2
23
1

â€¦with the following lunchbox which can be converted to â€¦

â€™s with on the bottom-right
â†’ Can be converted to
1
1

Then: There will be the same item () in both t and m.

Because of this, if we donâ€™t do anything, it wonâ€™t be able to calculate .

is in both t and m
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1
Because thereâ€™s a conflict in
t and m,
If we donâ€™t do anything, it wonâ€™t be
able to calculate

However, the special rule applies in this case:

• If the same item appears in both t and mâ€¦
• It will automatically change conflicting tâ€™s to something different.
Warning: Same item in t m
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1
Special rule:
Change t to something else
1
t
t
1
t
t
1
l
1
m
m
13
r
2
r
r
23
r
1

By doing this, it will be able to calculate .

I get it, but I donâ€™t know if I can remember to use this ruleâ€¦

Donâ€™t worry: This special rule will appear starting from the next page, but you donâ€™t have to memorize it. It will just happen automatically.

You just need to know that these rules exist, and you should be fine.

Slide 9 / 9

### What happens now?

Anyway: We figured out how to reproduce the â€śPlus 1â€ť feature .

As you promised, give us our mathboxes back!

Grrâ€¦

Will the villagers get their mathboxes back? Letâ€™s see on the next page.

Go to Next PageContinue to Intermediate 5
1 more intermediate level left!

### Before you take a breakâ€¦

Before you go: Iâ€™d really appreciate it if you could retweet the following tweet before closing this page.

If you have a question or a comment: Please reply to the above tweet with a screenshot, or email me at shu.chibicode@gmail.com. You can also discuss this on Hacker News.

If youâ€™re a programmer:

To keep reading this course: Press the button below!

Go to Next PageContinue to Intermediate 5
1 more intermediate level left!