The Gauntlet | Think Like A Coder, Ep 8
-
0:22 - 0:25Their fall from the tower sends
Ethic and Hedge -
0:25 - 0:29spinning into the rapids
of a river of pure energy. -
0:31 - 0:37This torrent flows from the Bradbarrier
all the way to Huxenborg. -
0:37 - 0:40There an entire city’s worth of factories
-
0:40 - 0:43build the robots
and house the Node of Memory, -
0:43 - 0:47the last of the three powerful artifacts
Ethic needs to collect. -
0:47 - 0:50After a long day and a longer night
-
0:50 - 0:54they find themselves
in a canyon of brick and steel. -
0:59 - 1:02Just when they’re about to reach
the end of the line, -
1:02 - 1:03a rope catches them.
-
1:07 - 1:11Their savior, Lemma,
has been waiting for them. -
1:11 - 1:15When Ethic claimed the Node of Creation
from the forest tower, -
1:15 - 1:19radios all across the land
came back to life. -
1:19 - 1:24Adila, the resistance leader,
immediately started contacting her allies, -
1:24 - 1:26none more important than Lemma,
-
1:26 - 1:32a brilliant scientist working from within
Huxenborg to bring down the machines. -
1:32 - 1:36Unfortunately, the radios
also tipped off the robots. -
1:36 - 1:39So they’ve taken defensive measures
-
1:39 - 1:43to protect the final artifact in its home
in the very heart of the city. -
1:43 - 1:49There’s only one way to get there:
the gauntlet of forking paths. -
1:49 - 1:55It’s a deadly series of luminous conveyors
that wind underneath Huxenborg. -
1:55 - 1:57Starting from the current position,
-
1:57 - 2:01each section runs for a distance,
then splits in two. -
2:01 - 2:05Every branch does the same thing,
again and again. -
2:05 - 2:07There are thousands of branches.
-
2:07 - 2:13Only one path leads to the artifact;
all the others to destruction. -
2:13 - 2:18Fortunately, the Node of Creation
has granted Hedge a strange power: -
2:18 - 2:21he can produce slightly smaller versions
of himself. -
2:21 - 2:26Each version can do only two things:
radio information back to its parent, -
2:26 - 2:30and produce slightly smaller
versions of itself… -
2:30 - 2:34which can do the same two things,
as can their children, -
2:34 - 2:37for as many generations as needed.
-
2:37 - 2:42A patrol is closing in on their position,
so Ethic’s time is limited. -
2:42 - 2:47What instructions should she give
Hedge to find the one safe path? -
2:47 - 2:54Pause the video to figure it out yourself.
-
2:54 - 2:55Hint in 3
-
2:55 - 2:56Hint in 2
-
2:56 - 2:57Hint in 1
-
2:58 - 3:03Programmers have an elegant tool
in their arsenal called recursion. -
3:03 - 3:08Recursion is when you have a set of
instructions that refers back to itself. -
3:08 - 3:11It’s like using a word
in its own definition, -
3:11 - 3:16except where that’s frowned upon,
this is incredibly effective. -
3:16 - 3:20Recursion involves repetition,
but in a different way than loops. -
3:20 - 3:24Where a loop takes one action
and repeats it again and again, -
3:24 - 3:29recursion will start an action,
and before it’s finished, use it again, -
3:29 - 3:33and before that’s finished,
use it again, and so on. -
3:33 - 3:37It keeps doing this until
some end state is reached. -
3:37 - 3:41It then passes the information back up,
layer after layer, -
3:41 - 3:44until it reaches the top
and ends the cycle. -
3:44 - 3:49Recursion is ideal for problems
that involve self-similarity, -
3:49 - 3:52where each part resembles
the larger whole. -
3:52 - 3:58Like, for example, a deadly defense
system designed to end any person or thing -
3:58 - 4:00who dares tread upon it.
-
4:00 - 4:02Pause the video to figure it out yourself.
-
4:02 - 4:03Solution in 3
-
4:03 - 4:04Solution in 2
-
4:04 - 4:05Solution in 1
-
4:05 - 4:08Ethic’s conundrum seems sprawling
on the surface, -
4:08 - 4:12but there’s a remarkably simple
solution to it using recursion. -
4:12 - 4:17In order to find it, let’s first look
at the simplest version of this puzzle: -
4:17 - 4:20what if the entire maze
were just two paths? -
4:20 - 4:25If Hedge copies himself, the copy
that goes the wrong way will be destroyed. -
4:25 - 4:28So the other one,
which will reach the artifact, -
4:28 - 4:32can radio back the path it took,
and then no matter which way is correct, -
4:32 - 4:35that’s the answer Hedge will receive.
-
4:35 - 4:38This is called the "base case"
of the recursion. -
4:38 - 4:42Now, suppose the maze
branches twice from the starting point, -
4:42 - 4:45and at every intersection,
Hedge’s copies— -
4:45 - 4:48let’s call them Twig 1 and Twig 2—
-
4:48 - 4:53make more copies—
let’s call them Leaves 1 through 4. -
4:53 - 4:56Three Leaves will be destroyed.
-
4:56 - 5:00The one that reaches the artifact
will radio back the right answer, -
5:00 - 5:02but only to its parent.
-
5:02 - 5:06So if Twig 1 or 2 is waiting
at an intersection -
5:06 - 5:08and hears something over the radio,
-
5:08 - 5:11that’s the right way to go
to the artifact from where it is. -
5:11 - 5:15To tell Hedge the right answer
from his perspective, -
5:15 - 5:17the Twig should say which way it went,
-
5:17 - 5:21and then the route
it just heard over the radio. -
5:21 - 5:25This same process will work no matter
how many times the maze branches. -
5:25 - 5:28Any answer a copy hears on the radio
-
5:28 - 5:32must be the way to the control room
from its location, -
5:32 - 5:34and if it then adds the branch it took,
-
5:34 - 5:37it can tell its parent
how to get there as well. -
5:37 - 5:41We can sum up the instructions
in an action called Pathfinder -
5:41 - 5:44that every version of Hedge will follow:
-
5:44 - 5:471. If you’ve reached the artifact,
-
5:47 - 5:51radio to your parent whether
you got there by going left or right. -
5:51 - 5:552. When you reach an intersection,
move off the conveyor -
5:55 - 5:59and send new copies down the left
and right paths. -
5:59 - 6:01Have them each run Pathfinder.
-
6:01 - 6:03This is where recursion comes in,
-
6:03 - 6:08and this may happen many times before
the last instruction triggers, which is: -
6:08 - 6:133. If you hear anything over the radio,
you should radio to your parent -
6:13 - 6:17whether you got to your spot
by going left or right, -
6:17 - 6:19then repeat everything you just heard.
-
6:19 - 6:23Pathfinder is an example
of what programmers call functions, -
6:23 - 6:26subroutines, or procedures.
-
6:26 - 6:30No matter the terminology,
the idea is the same— -
6:30 - 6:34it’s a set of instructions given a label
so that it can be easily reused— -
6:34 - 6:37perhaps even by itself.
-
6:37 - 6:40And in our case that’ll work perfectly—
-
6:40 - 6:45an entire network of paths mapped
using just three instructions. -
6:46 - 6:48So here's what happens.
-
7:10 - 7:16By the time the patrol rounds the corner,
Ethic and Lemma have improvised disguises. -
7:16 - 7:20They try to confuse the bots
long enough to buy Hedge time. -
7:31 - 7:36Finally, Hedge’s radio crackles to life
with a series of directions. -
7:36 - 7:40The three dive onto the conveyor
and flee for their lives, -
7:40 - 7:44with a squadron of enforcer bots
in hot pursuit.
- Title:
- The Gauntlet | Think Like A Coder, Ep 8
- Speaker:
- Alex Rosenthal
- Description:
-
View full lesson: https://ed.ted.com/lessons/the-gauntlet-think-like-a-coder-ep-8
This is episode 8 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.
- Video Language:
- English
- Team:
- closed TED
- Project:
- TED-Ed
- Duration:
- 08:01
lauren mcalpine approved English subtitles for The Gauntlet | Think Like A Coder, Ep 8 | ||
lauren mcalpine accepted English subtitles for The Gauntlet | Think Like A Coder, Ep 8 | ||
lauren mcalpine edited English subtitles for The Gauntlet | Think Like A Coder, Ep 8 | ||
Tara Ahmadinejad edited English subtitles for The Gauntlet | Think Like A Coder, Ep 8 | ||
Tara Ahmadinejad edited English subtitles for The Gauntlet | Think Like A Coder, Ep 8 |