The Gauntlet | Think Like A Coder, Ep 8

391,786 views ・ 2020-04-16

TED-Ed


Please double-click on the English subtitles below to play the video.

Translator: Reviewer: Thomas Tam
[TED-Ed 原創系列]
《像程式員思考噉》
[上回地點:198 樹林]
[今回地點:Huxenborg]
[第八集:挑戰]
00:21
Their fall from the tower sends Ethic and Hedge
0
21734
3050
Ethic、Hedge 從高塔墮下
00:24
spinning into the rapids of a river of pure energy.
1
24784
4240
陷入咗湍急嘅純能量河流
00:30
This torrent flows from the Bradbarrier all the way to Huxenborg.
2
30944
5937
呢股洪流從 Bradbarrier 一路流向 Huxenborg
00:36
There an entire city’s worth of factories
3
36881
3100
呢度整個城市嘅工廠 制造機械人
00:39
build the robots and house the Node of Memory,
4
39981
3080
同時存放咗「記憶節點」:
係 Ethic 要收集 三大神器最後一件
00:43
the last of the three powerful artifacts Ethic needs to collect.
5
43061
4372
00:47
After a long day and a longer night
6
47433
2510
佢哋渡過咗漫長嘅日 同夜
00:49
they find themselves in a canyon of brick and steel.
7
49943
3720
然後發現置身喺磚塊同鋼鐵嘅峽谷度
00:58
Just when they’re about to reach the end of the line,
8
58918
2655
正喺急流盡頭 快要滑落峽谷
01:01
a rope catches them.
9
61573
1750
一根從天而降嘅繩 抓住咗佢哋
01:07
Their savior, Lemma, has been waiting for them.
10
67023
4114
Lemma 呢個救星 一直等緊佢哋
01:11
When Ethic claimed the Node of Creation from the forest tower,
11
71137
3952
當 Ethic 從森林嘅塔度 奪取咗「創造節點」
01:15
radios all across the land came back to life.
12
75089
3900
通訊電波喺所有地方都恢復咗
01:18
Adila, the resistance leader, immediately started contacting her allies,
13
78989
4776
反抗組織領袖 Adila 立即聯絡佢嘅盟友
01:23
none more important than Lemma,
14
83765
2610
至醒天才 Lemma :
01:26
a brilliant scientist working from within Huxenborg to bring down the machines.
15
86375
5893
喺 Huxenborg 內部 做摧毀機械人嘅科學家
好不幸,無線電同樣驚動咗機械人
01:32
Unfortunately, the radios also tipped off the robots.
16
92268
4000
01:36
So they’ve taken defensive measures
17
96268
2260
所以機械人已採取咗防禦措施
01:38
to protect the final artifact in its home in the very heart of the city.
18
98528
4828
保護喺城市中心基地 僅存嘅最後神器
01:43
There’s only one way to get there: the gauntlet of forking paths.
19
103356
5155
其實只有一個方法嚟到呢度 係挑戰分叉路
01:48
It’s a deadly series of luminous conveyors that wind underneath Huxenborg.
20
108511
6386
喺 Luxembourg 下底 有一系列致命發光傳送帶
從而家呢個位置開始
01:54
Starting from the current position,
21
114897
1820
01:56
each section runs for a distance, then splits in two.
22
116717
4395
每段路前進一段距離 會分叉成兩條路
02:01
Every branch does the same thing, again and again.
23
121112
3430
每條分叉路,都不斷重覆之前嘅情況
02:04
There are thousands of branches.
24
124542
2400
分叉口會有成幾千個
02:06
Only one path leads to the artifact; all the others to destruction.
25
126942
5942
只係進入咗正確嘅路徑 先搵到神器,否則都會被消滅
02:12
Fortunately, the Node of Creation has granted Hedge a strange power:
26
132884
4619
好彩「創造節點」 畀咗 Hedge 一種神奇力量:
02:17
he can produce slightly smaller versions of himself.
27
137503
3720
佢可以自我複製,不過細少少
02:21
Each version can do only two things: radio information back to its parent,
28
141223
5210
複製品只可做兩件事: 將無線電信號傳回父級複製品
02:26
and produce slightly smaller versions of itself…
29
146433
3740
同時複製較少嘅自己……
02:30
which can do the same two things, as can their children,
30
150173
3690
全部複製品都可以做呢兩件事
02:33
for as many generations as needed.
31
153863
2940
按佢哋嘅需要製造複製品
02:36
A patrol is closing in on their position, so Ethic’s time is limited.
32
156803
5051
一支巡邏隊正行近 Ethic 嘅時間有限
佢應該畀啲乜嘢嘅指示 Hedge 嚟搵到條安全嘅路徑呢?
02:41
What instructions should she give Hedge to find the one safe path?
33
161854
5203
02:47
Pause the video to figure it out yourself.
34
167057
6778
按停 video 等自己搞清楚
02:53
Hint in 3
35
173835
990
[ 答案揭曉:3 ]
02:54
Hint in 2
36
174825
1200
[ 答案揭曉:2 ]
02:56
Hint in 1
37
176025
960
[ 答案揭曉:1 ]
02:57
Programmers have an elegant tool in their arsenal called recursion.
38
177825
5162
喺程式員武器庫度 有個優雅嘅工具叫做遞歸
03:02
Recursion is when you have a set of instructions that refers back to itself.
39
182987
5341
遞歸係一組會自我呼叫嘅程式
03:08
It’s like using a word in its own definition,
40
188328
2960
呢嗰就似係自己定義一個詞
03:11
except where that’s frowned upon, this is incredibly effective.
41
191288
4560
除非遞歸遇到設定嘅離開條件 其實係勁有效率嘅
03:15
Recursion involves repetition, but in a different way than loops.
42
195848
4512
遞歸涉及重複,但同迴圈唔同
03:20
Where a loop takes one action and repeats it again and again,
43
200360
4000
迴圈係就住一個動作,重複又重複
03:24
recursion will start an action, and before it’s finished, use it again,
44
204360
4302
遞歸將開始一個動作 直至完成前
03:28
and before that’s finished, use it again, and so on.
45
208662
4000
一再使用佢
03:32
It keeps doing this until some end state is reached.
46
212662
4000
佢一直噉做,直到遇見最後狀況
03:36
It then passes the information back up, layer after layer,
47
216662
4162
之後就一層層噉將資訊回報返父級
03:40
until it reaches the top and ends the cycle.
48
220824
3620
直到佢達到頂層同結束循環為止
03:44
Recursion is ideal for problems that involve self-similarity,
49
224444
4662
遞歸係理想嘅 處理涉及相似性循環嘅問題
03:49
where each part resembles the larger whole.
50
229106
2860
每部分都與更大整體邏輯相似
03:51
Like, for example, a deadly defense system designed to end any person or thing
51
231966
6004
例如一個防禦系統嘅目的
係消滅任何膽敢闖進去嘅人
03:57
who dares tread upon it.
52
237970
1890
03:59
Pause the video to figure it out yourself.
53
239860
2060
按停 video 搞清楚
04:01
Solution in 3
54
241920
793
[ 答案揭曉:3 ]
04:02
Solution in 2
55
242713
920
[ 答案揭曉:2 ]
04:03
Solution in 1
56
243633
1080
[ 答案揭曉:1 ]
04:04
Ethic’s conundrum seems sprawling on the surface,
57
244993
3041
Ethic 似乎撞到個辣手問題
04:08
but there’s a remarkably simple solution to it using recursion.
58
248034
4366
但係使用遞歸係勁簡單嘅解決方法
04:12
In order to find it, let’s first look at the simplest version of this puzzle:
59
252400
4750
為咗搵到神器 先睇下最簡單謎題嘅版本:
04:17
what if the entire maze were just two paths?
60
257150
3270
整個迷宮如果只係有兩條路?
04:20
If Hedge copies himself, the copy that goes the wrong way will be destroyed.
61
260420
4618
如果 Hedge 嘅複製品走錯路 將會被消滅
04:25
So the other one, which will reach the artifact,
62
265038
2719
而另一個就會搵到神器
04:27
can radio back the path it took, and then no matter which way is correct,
63
267757
4700
而且仲傳回佢行嘅正確路徑
Hedge 會得到呢個答案
04:32
that’s the answer Hedge will receive.
64
272457
2401
04:34
This is called the "base case" of the recursion.
65
274858
3580
呢種稱為遞歸嘅「基本情況」
04:38
Now, suppose the maze branches twice from the starting point,
66
278438
3340
依家,假設迷宮從起點分叉兩次
04:41
and at every intersection, Hedge’s copies—
67
281778
2982
Hedge 嘅複製品喺每個路口
04:44
let’s call them Twig 1 and Twig 2—
68
284760
2860
姑且叫做 1 號、2 號——
04:47
make more copies— let’s call them Leaves 1 through 4.
69
287620
5007
製作更多複製品—— 佢哋為葉子 1 到 4
04:52
Three Leaves will be destroyed.
70
292627
3120
三個葉子會被消滅咗
04:55
The one that reaches the artifact will radio back the right answer,
71
295747
4116
當一個搵到神器 會傳回正確嘅答案
04:59
but only to its parent.
72
299863
1980
但僅限對上嘅一層
05:01
So if Twig 1 or 2 is waiting at an intersection
73
301843
3880
若果 1 同 2 號分枝喺分叉路口等候
05:05
and hears something over the radio,
74
305723
1990
其中一個收到回音
05:07
that’s the right way to go to the artifact from where it is.
75
307713
3560
係從佢嘅位置 到搵到神器嘅正確方向
05:11
To tell Hedge the right answer from his perspective,
76
311273
3290
傳回畀 Hedge 嘅正確答案
05:14
the Twig should say which way it went,
77
314563
2440
分枝會報告佢先前嘅路徑
然後係佢啱啱通過無線電接收嘅路線
05:17
and then the route it just heard over the radio.
78
317003
3600
05:20
This same process will work no matter how many times the maze branches.
79
320603
4790
無論迷宮分支多少次 方法仍然有效
05:25
Any answer a copy hears on the radio
80
325393
2960
Hedge 會收到複製品嘅回音
05:28
must be the way to the control room from its location,
81
328353
3300
必須係從佢嘅位置到控制室嘅路徑
05:31
and if it then adds the branch it took,
82
331653
2350
再添加佢所採用嘅分支路徑
05:34
it can tell its parent how to get there as well.
83
334003
3220
佢告訴上一層點樣到達嗰度
05:37
We can sum up the instructions in an action called Pathfinder
84
337223
4000
我哋喺名為 Pathfinder 度總結指令
05:41
that every version of Hedge will follow:
85
341223
3130
Hedge 嘅每個複製品都將依照:
05:44
1. If you’ve reached the artifact,
86
344353
2290
1. 如果搵到神器嘅話
05:46
radio to your parent whether you got there by going left or right.
87
346643
4094
無論你係向左定向右 都可以通過無線電告訴上一層
05:50
2. When you reach an intersection, move off the conveyor
88
350737
3830
2. 當佢到達十字路口時 要離開傳送帶
05:54
and send new copies down the left and right paths.
89
354567
3980
並沿左右路徑發送新副本
05:58
Have them each run Pathfinder.
90
358547
2280
等佢哋各自運行 Pathfinder
06:00
This is where recursion comes in,
91
360827
2040
呢個就係遞歸嘅用處
06:02
and this may happen many times before the last instruction triggers, which is:
92
362867
5094
喺觸發最後指令之前會發生好多次
06:07
3. If you hear anything over the radio, you should radio to your parent
93
367961
4987
3. 當複製品收到傳回嘅無線電 就會報告上一層
06:12
whether you got to your spot by going left or right,
94
372948
3629
無論你係向左定向右走 嚟到你現時位置
06:16
then repeat everything you just heard.
95
376577
2850
仲複述你啱啱聽到嘅一切
06:19
Pathfinder is an example of what programmers call functions,
96
379427
3996
Pathfinder 係程式員 呼叫函數、子程序
或者過程嘅一個例子
06:23
subroutines, or procedures.
97
383423
2690
06:26
No matter the terminology, the idea is the same—
98
386113
3390
唔理用乜嘢術語 諗法都係一樣——
06:29
it’s a set of instructions given a label so that it can be easily reused—
99
389503
4794
佢係一組帶有說明嘅標籤 方便輕鬆噉重複使用——
06:34
perhaps even by itself.
100
394297
2310
甚至可能係佢自己噉簡單
06:36
And in our case that’ll work perfectly—
101
396607
2976
喺我哋嘅例子度完美噉工作——
06:39
an entire network of paths mapped using just three instructions.
102
399583
5230
僅係使用三個指令 就能夠探測到整個路徑嘅網絡
06:46
So here's what happens.
103
406257
1630
呢個就係會發生嘅嘢
07:09
By the time the patrol rounds the corner, Ethic and Lemma have improvised disguises.
104
429760
5777
當巡邏隊拐到拐角處時 Ethic 和 Lemma 已經即興偽裝
07:15
They try to confuse the bots long enough to buy Hedge time.
105
435537
4120
試圖蒙騙機械人 等 Hedge 有足夠時間
07:31
Finally, Hedge’s radio crackles to life with a series of directions.
106
451473
4778
最後,Hedge 收到無線電 一系列嘅指示
三人跳上傳送帶逃命
07:36
The three dive onto the conveyor and flee for their lives,
107
456251
3850
一群執法嘅機器人跟得好貼
07:40
with a squadron of enforcer bots in hot pursuit.
108
460101
3720
About this website

This site will introduce you to YouTube videos that are useful for learning English. You will see English lessons taught by top-notch teachers from around the world. Double-click on the English subtitles displayed on each video page to play the video from there. The subtitles scroll in sync with the video playback. If you have any comments or requests, please contact us using this contact form.

https://forms.gle/WvT1wiN1qDtmnspy7