|
|
AlexRosenthal_ThinkLikeACoderS001E006_2019E-
|
Ethic , Hedge , and Octavia stand on the edge of a bottomless ravine . |
艾斯克、海吉和奥克塔维亚 站在无底峡谷的边缘。 |
Ethic:n.伦理;道德规范;adj.伦理的;道德的(等于ethical); Hedge:n.树篱; v.避免正面回答; adj.树篱的; on the edge of:adv.几乎;濒于;在…边缘; bottomless:adj.无底的;深不可测的;难解的;取之不尽的; ravine:n.沟壑,山涧;峡谷;
|
It’s the only thing between them and the tower that houses the second of three powerful artifacts . |
峡谷是他们与塔之间的唯一阻碍, 塔里藏有三个强大神器中的第二个。 |
artifacts:n.史前古器物;人工产品;
|
They’ve got a brief window of time to get across before the guards return. |
他们在警卫回来前 |
With Hedge’s fuel gauge on empty he won’t be able to fly Ethic across, so the only option is to make a bridge. |
海吉的燃料箱空了, 无法带艾斯克飞越过去, 所以,唯一选择是建一座桥。 |
gauge:n.计量器;标准尺寸;容量规格;vt.测量;估计;给…定规格; option:n.选择;可选择的东西;
|
Fortunately , the floating stacks of stones nearby are bridge components— invented by Octavia herself— called hover-blocks. |
幸运的是,附近漂浮的石头堆 可以用来搭一座桥, 石头堆是奥克塔维亚 自己发明的—— |
Fortunately:adv.幸运地; stacks:n.堆叠;[图情]书库(stack的复数);进程堆栈应用; nearby:adj.附近的,邻近的;adv.在附近;prep.在…附近;
|
Activate a pile with a burst of energy, and they’ll self-assemble to span the ravine as Ethic walks across. |
他们可以用一股能量 激活一堆飘浮块, 这样在这些飘浮块自动组装时, 艾斯克就能跨越峡谷。 |
Activate:vt.刺激;使活动;使活泼;使产生放射性;vi.激活;有活力; pile:n.桩;堆;摞;桩柱;v.堆放;摞起;叠放;放置; burst:v.破裂;爆炸;突破;冲进;n.爆发;点射;释放;(情感的)迸发; self-assemble:vi.自组装; span:n.持续时间; v.持续;
|
But there is, of course, a catch. |
但现在存在一个问题。 |
The hover-blocks are only stable when they’re perfectly palindromic. |
这些飘浮块只有在组合成 完美的回文结构时才能保持稳定。 |
stable:n.马厩;牛棚;adj.稳定的;牢固的;坚定的;vi.被关在马厩;赶入马房;
|
Meaning they have to form a sequence that’s the same when viewed forwards and backwards. |
也就是说,它们得被组合成 正序看和倒序看都一致的结构才行。 |
sequence:n.顺序; v.按顺序排列;
|
The stacks start in random orders, but will always put themselves into a palindromic configuration if they can. |
飘浮块最初是随机排列的, 但如果可行, |
random:adj.[数]随机的;任意的;胡乱的;n.随意;adv.胡乱地; configuration:n.配置;结构;外形;
|
If they get to a point where a palindrome isn’t possible, the bridge will collapse , and whoever’s on it will fall into the ravine. |
但如果它们无法被拼成回文结构, 桥就会坍塌掉, 走在上面的人就会坠入深谷。 |
palindrome:n.回文; collapse:vi.倒塌;瓦解;暴跌;vt.使倒塌,使崩溃;使萎陷;折叠;n.倒塌;失败;衰竭;
|
Let’s look at an example. |
让我们来看一个例子。 |
This stack would make itself stable. |
这堆飘浮块能被组成稳定的结构。 |
First the A blocks hold themselves in place. |
首先,A 型方块 能被排列在左右两侧。 |
And finally the C would nestle right between the B’s. |
最后,C 型方块正好 能被放在两块 B 之间。 |
finally:adv.终于;最终;(用于列举)最后;彻底地; nestle:vi.舒适地坐定;偎依;半隐半现地处于;vt.抱;安置;
|
However, suppose there was one more A. |
但假设多一块 A 型方块的话。 |
suppose:v.推断:假定:假设:设想:
|
First two A blocks form up, then two B’s, but now the remaining C and A have nowhere to go, so the whole thing falls apart. |
首先两块 A 排列好, 然后两块 B 也排列好, 但剩下的 A 块 和 C 块就没地方放了, 因此整座桥都会塌掉。 |
nowhere:v.无处; n.无处; adj.不存在的;
|
The Node of Power enables Hedge to energize a single stack of blocks. |
力量节点晶石只够海吉 激活一堆飘浮块, |
Node:n.节点;结点;茎节;(根或枝上的)节; enables:v.使得; (enable的第三人称单数) energize:v.使充满热情;增添能量(或精力、活力、干劲);为…提供电力(或能量);
|
What instructions can Ethic give Hedge to allow him to efficiently find and power a stable palindromic stack? |
艾斯克要给海吉什么指令, 才能让它有效地找到并激活 一堆稳固且为回文结构的飘浮块呢? |
efficiently:adv.有效地;效率高地(efficient的副词形式);
|
Pause now to figure it out for yourself. |
[ 可暂停播放自行解题 ] |
Examples of palindromes include ANNA, RACECAR , and MADAM IM ADAM. |
回文排列的例子如:ANNA、RACECAR、 以及 MADAM IM ADAM。 |
palindromes:n.回文;(细胞中遗传物质的)回文结构;(palindrome的复数) RACECAR:n.赛车;
|
Counting the number of times a given letter appears in a palindrome will reveal a helpful pattern. |
通过数一个字母 在回文中出现的次数, 你会发现一个有用的模式。 |
reveal:v.显示;透露;揭露;泄露;n.揭露;暴露;门侧,窗侧;
|
Pause now to figure it out for yourself. |
[ 可暂停播放自行解题 ] |
Let’s first look at a na?ve solution to this problem. |
我们先来看一个简单的方案。 |
solution:n.解决方案;溶液;溶解;解答;
|
A na?ve solution is a simple, brute-force approach that isn’t optimized— but will get the job done. |
简易方案是一种 但是它可以达成目标。 |
brute-force:n.强力攻击;蛮力; approach:n.方法;路径;v.接近;建议;着手处理;
|
Na?ve solutions are helpful ways to analyze problems, and work as stepping stones to better solutions. |
简单方案是分析问题的有用方法, 是更优方案的铺路石。 |
analyze:v.对…进行分析,分解(等于analyse);
|
In this case, a na?ve solution is to approach a pile of blocks, try all the arrangements , and see if one is a palindrome by reading it forward and then backwards. |
在这种情况下,一个简单方案是: 尝试这堆飘浮块的所有可能组合, 并通过正向,反向阅读 来确定其是否为回文结构。 |
arrangements:n.安排;筹备;布置;商定;(arrangement的复数)
|
The problem with this approach is that it would take a tremendous amount of time. |
但这种方法有个缺陷, 它需要大量的时间。 |
tremendous:adj.极大的,巨大的;惊人的;极好的;
|
If Hedge tried one combination every second, |
如果海吉每秒 能判断一种组合可不可行, |
combination:n.结合;组合;联合;[化学]化合;
|
That’s because the total time is a function of the factorial of the number of blocks there are. |
这是因为总时间 是总块数的阶乘。 |
factorial:adj.因子的,阶乘的;n.[数]阶乘;
|
10 blocks have over 3 million combinations . |
10 个飘浮块就有 超过 300 万种组合方式。 |
combinations:n.[数]组合;制品(combination的复数);合谱;
|
What this na?ve solution shows is that we need a much faster way to tell whether a pile of blocks can form a palindrome. |
这个简单的解决方案表明, 我们需要一种更快的方法 来判断一堆飘浮块 是否可以形成回文。 |
To start, it may be intuitively clear that a pile of all different blocks will never form one. |
首先,很明显的是, 一堆各不相同的飘浮块 永远不可能形成回文结构。 |
intuitively:adv.直观地;直觉地;
|
Why? |
为什么? |
The first and last blocks can’t be the same if there are no repeats. |
为什么? |
first and last:总的说来,整体看来;始终;主要地;
|
So when can a given sequence become a palindrome? |
那么什么时候一个给定的 序列可以形成回文呢? |
One way to figure that out is to analyze a few existing palindromes. |
一种方法是分析 一些现有的回文。 |
The pattern here is that most of the letters occur an even number of times, and there’s at most 1 that occurs just once. |
模式是,大多数字母 会出现偶数次, 最多只有一个字母 可以只出现一次。 |
occurs:v.重现(occur的第三人称单数);
|
Is that it? |
这就完了吗? |
What if RACECAR had 3 E’s instead of 1? |
如果 RACECAR 有3个 E 而不是1个呢? |
What if:如果…怎么办?
|
We could tack the new E’s onto the ends and still get a palindrome, so 3 is ok. |
我们可以把新的两个 E 钉在两端, 仍能得到一个回文, 所以字母出现 3 次是可以的。 |
But make that 3 E’s and 3 C’s, and there’s nowhere for the last C to go. |
但如果有 3 个 E 和 3 个 C , 最后一个 C 就没有地方放了。 |
So the most generalized insight is that at most one letter can appear an odd number of times, but the rest have to be even. |
让我们来概括一下思路, 最多只有一个字母能出现奇数次, 但其他字母必须出现偶数次。 |
generalized:adj.广义的,普遍的; v.推广(generalize的过去分词); insight:n.洞察力;洞悉; odd:adj.古怪的;奇数的;n.奇数;
|
Hedge can count the letters in each stack and organize them into a dictionary, which is a tidy way of storing information. |
海吉可以数每个字母 在飘浮堆中出现的次数, 这是一种储存信息的简洁方式。 |
organize:v.组织;安排;处理;分配;管理; tidy:adj.整齐的:整洁的:v.使整洁:
|
A loop could then go through and count how many times odd numbers appear. |
可以通过一个循环遍历这个字典, 数有几个字母出现了奇数次。 |
loop:n.循环;回路;环路;圈;v.使成环;使绕成圈;成环形移动;
|
If there are less than 2 odd characters, the stack can be made into a palindrome. |
如果有少于两个字母出现了奇数次, |
This approach is much, much faster than the na?ve solution. |
这种方法比之前的 那个简单解决方案要快得多。 |
Instead of factorial time, it takes linear time. |
它只需线性时间, 而不是阶乘时间。 |
linear:adj.线的,线型的;直线的,线状的;长度的;
|
That’s where the time increases in proportion to the number of blocks there are. |
线性时间指的是 程序运行时间与方块数量成正比。 |
in proportion to:与…成比例,与…相称;
|
Now write a loop for Hedge to approach the piles individually , and stop when he finds a good one, and you’ll be ready to go. |
现在,请你为海吉编写一个循环, 来分别处理这些飘浮块堆, 当它找到可行的方案时, 暂停程序,这样就成功了。 |
piles:n.痔疮;痔; individually:adv.个别地,单独地;
|
Here’s what happens: |
接下来会发生的是: |
Hedge is fast, but there are so many piles it takes a long time. |
虽然海吉的速度很快, |
Too long. |
很长很长的时间。 |
Ethic and Hedge are safe. |
艾斯克和海吉现在安全了, |
But Octavia is not so lucky. |
但奥克塔维亚就没那么幸运了。 |