Return to Video

The Resistance | Think Like A Coder, Ep 2

  • 0:22 - 0:25
    After breaking Ethic out of prison,
  • 0:25 - 0:28
    Hedge flies them both towards
    a frontier settlement
  • 0:28 - 0:35
    in the shadow of the Bradbarrier,
    the great wall that encircles the nation.
  • 0:35 - 0:39
    All the settlers there will soon gather
    for the monthly feeding.
  • 0:39 - 0:43
    The people of the wall spend their days
    gathering up works of art and literature,
  • 0:43 - 0:46
    from all across the land.
  • 0:46 - 0:50
    On feeding day, the furnace-bots arrive,
    ravenous.
  • 0:50 - 0:56
    If they eat, the lights stay on,
    and the food gets delivered.
  • 0:56 - 0:59
    If they starve, the people do too.
  • 1:01 - 1:06
    Hedge’s fuel supply runs out just as he
    and Ethic reach the outskirts of town,
  • 1:06 - 1:09
    and they come in for a crash landing.
  • 1:11 - 1:15
    Luckily, everyone is too busy preparing
    for the feeding to notice.
  • 1:15 - 1:18
    Today’s feeding is where Ethic
    can find the leader
  • 1:18 - 1:21
    of an underground resistance movement.
  • 1:21 - 1:25
    This person knows the location of the
    first of three powerful artifacts.
  • 1:25 - 1:27
    The problem is, Hedge and
    Ethic don’t know
  • 1:27 - 1:31
    the resistance leader’s name
    or appearance.
  • 1:31 - 1:35
    But Hedge has gathered the
    following information:
  • 1:35 - 1:37
    The leader has green eyes.
  • 1:37 - 1:43
    If the leader has red hair, their name has
    at least one consecutive double letter.
  • 1:43 - 1:48
    If the leader wear glasses,
    their name has exactly 2 vowels.
  • 1:48 - 1:52
    Otherwise, their name has
    exactly 3 vowels.
  • 1:52 - 1:57
    There is exactly one person for whom
    these are all true.
  • 1:57 - 1:58
    As a fugitive,
  • 1:58 - 2:03
    Ethic can’t sneak into the crowd without
    drawing attention to herself.
  • 2:03 - 2:05
    But she can give instructions to Hedge.
  • 2:05 - 2:10
    And one tool she has is what
    programmers call a conditional.
  • 2:10 - 2:13
    That’s a statement of the form
    “If A, then B.”
  • 2:13 - 2:16
    Flowcharts are great illustrations
    of how those work.
  • 2:16 - 2:22
    This conditional translates to:
    if A is true, carry out instruction B.
  • 2:22 - 2:26
    There are also conditionals that account
    for different possibilities.
  • 2:26 - 2:30
    This says, “If A is true, perform
    instruction B.
  • 2:30 - 2:34
    Otherwise, carry out instruction C.”
  • 2:34 - 2:39
    So what instructions does she give Hedge
    so he can find the resistance leader?
  • 2:39 - 2:43
    Pause now to figure it out for yourself.
  • 2:43 - 2:47
    With a problem like this,
    it can help to simplify first.
  • 2:47 - 2:51
    What if Hedge just has to examine
    this one person?
  • 2:51 - 2:54
    What information does he need
    to collect about her?
  • 2:54 - 2:57
    He might ask, “Does she have green eyes?”
  • 2:57 - 3:02
    What other questions should Hedge
    ask to find the resistance leader,
  • 3:02 - 3:06
    and how can he track those answers?
  • 3:06 - 3:11
    Pause now to figure it out for yourself.
  • 3:11 - 3:15
    It may seem intuitive how you’d approach
    this problem as a human.
  • 3:15 - 3:16
    But Hedge isn’t a human,
  • 3:16 - 3:21
    and so the challenge comes from needing
    to give him systematic instructions
  • 3:21 - 3:24
    that will work in any scenario.
  • 3:24 - 3:27
    Hedge needs to examine the settlers,
    one at a time,
  • 3:27 - 3:29
    until he discovers the right person.
  • 3:29 - 3:33
    In other words, like with the
    lock on the prison cell,
  • 3:33 - 3:37
    this is a loop that repeats the
    same instructions.
  • 3:37 - 3:40
    Only this time the loop will involve
    a series of questions
  • 3:40 - 3:42
    in the form of conditionals,
  • 3:42 - 3:45
    and will end as soon as Hedge
    finds his target.
  • 3:45 - 3:49
    But first, you’ll want to organize
    your information.
  • 3:49 - 3:55
    Each person has a set of characteristics:
    Eye color, hair color, glasses, and name.
  • 3:55 - 3:57
    Does this person have green eyes?
  • 3:57 - 4:02
    If so, mark a check next to “eye color."
    If not, mark an X there.
  • 4:02 - 4:06
    If they have red hair, does their
    name contain a double letter?
  • 4:06 - 4:10
    If so, mark a check next to “hair color.”
  • 4:10 - 4:14
    If they don’t have a double letter,
    mark an X next to “hair color.”
  • 4:14 - 4:19
    Anyone with red hair and no double
    letter can’t be the resistance leader.
  • 4:19 - 4:21
    But notice that if they have blue hair,
  • 4:21 - 4:25
    Hedge will skip this question and
    go on to the next one.
  • 4:25 - 4:28
    For the last question, we can say,
  • 4:28 - 4:33
    “If they wear glasses, does their name
    have exactly 2 vowels?
  • 4:33 - 4:38
    If they don’t have glasses, does their
    name have exactly 3 vowels?”
  • 4:38 - 4:42
    There will be people in the crowd with
    glasses and 1 vowel,
  • 4:42 - 4:45
    or no glasses and 2 vowels.
  • 4:45 - 4:49
    But they’re not who we’re looking for,
    so they’ll get X’s.
  • 4:49 - 4:52
    The resistance leader must be someone
    with either check marks
  • 4:52 - 4:55
    or blanks next to every question.
  • 4:55 - 4:58
    Blanks are ok, because if someone
    has blue hair,
  • 4:58 - 5:02
    the rule about red hair doesn’t
    apply to them.
  • 5:02 - 5:06
    You could have Hedge ask every question
    about every person,
  • 5:06 - 5:09
    and then choose the person with
    only checks and blanks.
  • 5:09 - 5:14
    But there’s a way to save yourself lots
    of time: as soon as Hedge marks an X,
  • 5:14 - 5:17
    have him move on to the next person.
  • 5:17 - 5:19
    You don’t need to know the answer
    to every question;
  • 5:19 - 5:24
    just one X means they’re not the target
    of your search.
  • 5:26 - 5:28
    Hedge buzzes through the crowd,
  • 5:28 - 5:32
    and within minutes finds Adila,
    the resistance leader,
  • 5:32 - 5:34
    and brings her back to Ethic.
  • 5:34 - 5:39
    Adila agrees to help them steal the first
    artifact— the node of power—
  • 5:39 - 5:41
    but under one condition:
  • 5:41 - 5:44
    that Ethic and Hedge jump-start
    the revolution
  • 5:44 - 5:48
    by reprogramming the furnace-bots
    that terrorize the town.
  • 5:48 - 5:51
    And right on cue, the robots descend.
Title:
The Resistance | Think Like A Coder, Ep 2
Speaker:
Alex Rosenthal
Description:

View full lesson: https://ed.ted.com/lessons/the-resistance-think-like-a-coder-ep-2

This is episode 2 of our animated series “Think Like A Coder.” This 10-episode narrative follows a girl, Ethic, and her robot companion, Hedge, as they attempt to save the world. The two embark on a quest to collect three artifacts and must solve their way through a series of programming puzzles.

Lesson by Alex Rosenthal, directed by Kozmonot Animation Studio.

more » « less
Video Language:
English
Team:
closed TED
Project:
TED-Ed
Duration:
05:54

English subtitles

Revisions Compare revisions