字幕列表 影片播放
-
Their fall from the tower sends Ethic and Hedge
譯者: Lilian Chiu 審譯者: H_L Au
-
spinning into the rapids of a river of pure energy.
《用程式設計師的方式思考》
-
This torrent flows from the Bradbarrier all the way to Huxenborg.
地點:哈林堡 地點:198 森林
-
There an entire city's worth of factories
第八集:挑戰
-
build the robots and house the Node of Memory,
艾希克和海吉從塔上落下之後,
-
the last of the three powerful artifacts Ethic needs to collect.
便天旋地轉地落入 純能量的急流當中。
-
After a long day and a longer night
這條洪流從八達圍 一路流到哈森堡。
-
they find themselves in a canyon of brick and steel.
在那裡,有相當於 一整個城市的工廠,
-
Just when they're about to reach the end of the line,
用來建造機器人和存放記憶之泉,
-
a rope catches them.
正是艾希克必須要收集的 三項強大寶物的最後一項。
-
Their savior, Lemma, has been waiting for them.
在經過漫長的一天 和更漫長的一夜之後,
-
When Ethic claimed the Node of Creation from the forest tower,
他們到了一個由磚塊 和鋼鐵形成的峽谷。
-
radios all across the land came back to life.
他們快要到達盡頭時,
-
Adila, the resistance leader, immediately started contacting her allies,
一條繩索套住了他們。
-
none more important than Lemma,
他們的救星雷瑪 一直在那裡等他們。
-
a brilliant scientist working from within Huxenborg to bring down the machines.
當艾希克從森林中的高塔 取得創造之泉時,
-
Unfortunately, the radios also tipped off the robots.
各地的無線電都恢復通訊了。
-
So they've taken defensive measures
反抗軍領袖艾迪拉馬上 就開始聯絡她的盟友,
-
to protect the final artifact in its home in the very heart of the city.
當中最重要的就是雷瑪了,
-
There's only one way to get there: the gauntlet of forking paths.
她是個聰明的科學家, 在哈森堡內部努力破壞機器。
-
It's a deadly series of luminous conveyors that wind underneath Huxenborg.
不幸的是,無線電 也將消息走漏給機器人。
-
Starting from the current position,
於是,它們採取了防禦措施,
-
each section runs for a distance, then splits in two.
保護身處在城市核心的 最後一項寶物。
-
Every branch does the same thing, again and again.
要到達只有一種方法,岔路挑戰。
-
There are thousands of branches.
這個挑戰是在哈森堡地下 一連串的致命迂迴發光輸送帶。
-
Only one path leads to the artifact; all the others to destruction.
從目前的位置開始,
-
Fortunately, the Node of Creation has granted Hedge a strange power:
每段輸送帶會輸送一段距離, 接著便一分為二。
-
he can produce slightly smaller versions of himself.
每個分支都會不斷重覆這個流程。
-
Each version can do only two things: radio information back to its parent,
總共有數千條分支。
-
and produce slightly smaller versions of itself…
只有一條路通往寶物,
-
which can do the same two things, as can their children,
其他則全部都通往死亡。
-
for as many generations as needed.
幸運的是,創造之泉 將一種奇特的力量賦予海吉:
-
A patrol is closing in on their position, so Ethic's time is limited.
它能製造出它自己的 複製品,但比較小。
-
What instructions should she give Hedge to find the one safe path?
每一個複製品都會做兩件事:
-
Pause the video to figure it out yourself.
把資訊用無線電回傳給它的母體,
-
Hint in 3
以及再複製出比較小的自己,
-
Hint in 2
而這些複製品同樣也會 做這兩件事,以此類推,
-
Hint in 1
有必要就可以一直產生新世代。
-
Programmers have an elegant tool in their arsenal called recursion.
巡邏兵正在靠近,所以時間有限。
-
Recursion is when you have a set of instructions that refers back to itself.
她應該給海吉什麼指令, 才能找到那唯一一條安全的通路?
-
It's like using a word in its own definition,
如果想要自己解題,請在此暫停。
-
except where that's frowned upon, this is incredibly effective.
提示即將公佈:五
-
Recursion involves repetition, but in a different way than loops.
提示即將公佈:三
-
Where a loop takes one action and repeats it again and again,
提示即將公佈:一
-
recursion will start an action, and before it's finished, use it again,
程式設計師有項利器,叫做遞迴。
-
and before that's finished, use it again, and so on.
當你有一組指令,又會導至 它自己本身時,就叫做遞迴。
-
It keeps doing this until some end state is reached.
就像是在一個詞的定義中 用到這個詞一樣,
-
It then passes the information back up, layer after layer,
差別在於不能使用它時, 這就是非常有效的方法。
-
until it reaches the top and ends the cycle.
遞迴會涉及重覆,但和迴圈不同。
-
Recursion is ideal for problems that involve self-similarity,
迴圈是不斷重覆同一個動作,
-
where each part resembles the larger whole.
遞迴會從一個動作開始, 在它結束之前,又再次使用它,
-
Like, for example, a deadly defense system designed to end any person or thing
在那結束之前, 又再使用它,以此類推。
-
who dares tread upon it.
遞迴會這樣不斷進行下去, 直到達成某種終止狀態。
-
Pause the video to figure it out yourself.
接著,就會把資訊一層一層回傳,
-
Solution in 3
直到資訊傳到頂層, 循環就此結束。
-
Solution in 2
遞迴很適合用來解決 和「自相似」有關的問題,
-
Solution in 1
也就是每個部分 都和更大的整體很相似。
-
Ethic's conundrum seems sprawling on the surface,
就像是這個致命的防禦系統,
-
but there's a remarkably simple solution to it using recursion.
設計的目的是要消滅 任何有膽踏上它的人或物。
-
In order to find it, let's first look at the simplest version of this puzzle:
如果想要自己解題,請在此暫停。
-
what if the entire maze were just two paths?
解答即將公佈
-
If Hedge copies himself, the copy that goes the wrong way will be destroyed.
艾希克的難題在表面上 看似雜亂無規則,
-
So the other one, which will reach the artifact,
但其實若會用遞迴, 就有一個非常簡單的解法。
-
can radio back the path it took, and then no matter which way is correct,
為了要解題,我們先來看看 這個謎題最簡單的版本:
-
that's the answer Hedge will receive.
如果整個迷宮只有兩條路呢?
-
This is called the "base case" of the recursion.
如果海吉複製它自己, 走錯路的複製品會被摧毀。
-
Now, suppose the maze branches twice from the starting point,
所以,另一個複製 就會抵達寶物所在,
-
and at every intersection, Hedge's copies—
用無線電回傳它走過的路徑資訊,
-
let's call them Twig 1 and Twig 2—
不論哪條路是對的路, 那就是海吉會收到的答案。
-
make more copies— let's call them Leaves 1 through 4.
這就叫做遞迴的「基本情況」。
-
Three Leaves will be destroyed.
假設迷宮從起始點開始 就有兩倍的岔路,
-
The one that reaches the artifact will radio back the right answer,
在每個路口,海吉的複製品——
-
but only to its parent.
咱們就稱它們為 小枝一號和小枝二號——
-
So if Twig 1 or 2 is waiting at an intersection
會產生更多複製品—— 稱為小葉一號到小葉四號。
-
and hears something over the radio,
會有三個小葉複製品被摧毀。
-
that's the right way to go to the artifact from where it is.
抵達寶物所在的那個小葉 會將正確答案用無線電回傳,
-
To tell Hedge the right answer from his perspective,
但只會傳給它的母體。
-
the Twig should say which way it went,
如果小枝一號 或小枝二號在路口等候,
-
and then the route it just heard over the radio.
從無線電聽到消息,
-
This same process will work no matter how many times the maze branches.
那就是從它的所在 通往寶物的正確路線。
-
Any answer a copy hears on the radio
小枝要從它的角度 把正確答案告訴海吉,
-
must be the way to the control room from its location,
就應該要說出它去過哪裡,
-
and if it then adds the branch it took,
以及它從無線電所聽到的路線。
-
it can tell its parent how to get there as well.
不論迷宮的分岔有多少, 同樣的流程都行得通。
-
We can sum up the instructions in an action called Pathfinder
任何複製品從無線電聽到的答案
-
that every version of Hedge will follow:
都是從它的所在 到達控制室的路徑,
-
1. If you've reached the artifact,
如果再加上它自己走的岔路,
-
radio to your parent whether you got there by going left or right.
它就可以告訴它的母體 如何到達那裡。
-
2. When you reach an intersection, move off the conveyor
我們可以把指令總整成 一個動作,叫做「找路程式」,
-
and send new copies down the left and right paths.
每個版本的海吉複製品 都要遵循這個程式:
-
Have them each run Pathfinder.
一、如果你到了寶物的所在,
-
This is where recursion comes in,
用無線電告訴你的母體你怎麼走到 那裡(用左轉、右轉來表述)。
-
and this may happen many times before the last instruction triggers, which is:
二、當你到達路口時, 離開輸送帶,
-
3. If you hear anything over the radio, you should radio to your parent
派遣新的複製品 去走左、右兩條路。
-
whether you got to your spot by going left or right,
要求它們都要執行「找路程式」。
-
then repeat everything you just heard.
這就是要用到遞迴的地方了,
-
Pathfinder is an example of what programmers call functions,
這個指令可能要執行許多次, 才會啟動最後一個指令,即:
-
subroutines, or procedures.
三、如果你從無線電收到資訊, 你就要用無線電聯絡你的母體,
-
No matter the terminology, the idea is the same—
說明你是怎麼到你的所在 (用左轉、右轉來表述),
-
it's a set of instructions given a label so that it can be easily reused—
接著再重述你從無線電 聽到的所有資訊。
-
perhaps even by itself.
「找路程式」就是程式設計師
-
And in our case that'll work perfectly—
所謂的函數、子程式,或程序。
-
an entire network of paths mapped using just three instructions.
不論用哪個術語稱呼, 背後的想法都相同——
-
So here's what happens.
把一組指令包裝起來, 貼上標籤,方便重覆使用——
-
By the time the patrol rounds the corner, Ethic and Lemma have improvised disguises.
甚至可以被它自己使用。
-
They try to confuse the bots long enough to buy Hedge time.
在我們的例子中, 採用它就非常完美——
-
Finally, Hedge's radio crackles to life with a series of directions.
只用三條指令 就能繪製出整個網絡。
-
The three dive onto the conveyor and flee for their lives,
接著發生的狀況是:
-
with a squadron of enforcer bots in hot pursuit.
當巡邏兵到轉角時,