返回首页

AlexRosenthal_ThinkLikeACoderS001E005_2019E-

Dawn and the train are both breaking when Ethic and Hedge arrive in the woods. 破晓时分,火车停下, 艾斯克和海吉抵达了树林。
Dawn:n.黎明;开端;vt.破晓;出现;被领悟; Ethic:n.伦理;道德规范;adj.伦理的;道德的(等于ethical); Hedge:n.树篱; v.避免正面回答; adj.树篱的;
The adventurers have recovered the first artifact— and have come to the 198forest in search of the second. 这两位冒险者 已找到第一件神器 —— 现抵达 198 森林, 来找寻第二件神器,
adventurers:n.冒险家;投机商(adventurer的复数);
Here they’re welcomed by the director of the colony , Octavia. 殖民首领奥克塔维亚 欢迎他们的到来。
colony:n.殖民地;移民队;
She established this treehouse sanctuary after the robots freed everyone from having to work. 机器人把人们从工作中解放后, 她建立了这个树屋保护区。
established:adj.已确立的;著名的;v.建立;创立;设立;(establish的过去分词和过去式) treehouse:n.树上小屋(供儿童游戏用); sanctuary:n.避难所;至圣所;耶路撒冷的神殿;
It was meant to be a haven where people could follow their passions , take up crafts, and find fulfillment . 这本应是人们追随自己激情、 从事手工业,获得成就感的港湾,
haven:n.避难所;保护区;v.把船开进港;掩护; passions:n.强烈情感;激情;盛怒;(passion的复数) fulfillment:n.履行;实行;
Which they did… at first. 一开始,人们也确实是这么做的,
Some years ago everyone forgot the point. 但几年前,大家都忘记了初衷,
They abandoned arts and crafts and instead just painted and exhibited pictures of themselves over, and over, and over. 他们放弃了艺术和手工, 只是不停地画自己, 并展示自己的照片, 日复一日,年复一年。
abandoned:adj.被抛弃的放纵的;v.抛弃;丢弃,离开;放弃;(abandon的过去分词和过去式) arts and crafts:n.手工艺; exhibited:adj.展出的;v.展出;表现出(exhibit的过去分词);
The location of the second artifact is no secret; it’s in a tower, guarded by a garrison of bots , a bottomless ravine , and who knows what other traps . 第二件神器的位置众所周知, 位于一个万丈深谷的塔里, 由机器人看守, 有众多不为人知的陷阱。
location:n.地方;地点;位置;定位 artifact:n.人工制品;手工艺品; garrison:n.要塞;卫戍部队;vt.驻防;守卫; bots:n.蝇蛆病; v.只想借不想还(bot的第三人称单数形式); bottomless:adj.无底的;深不可测的;难解的;取之不尽的; ravine:n.沟壑,山涧;峡谷; traps:n.陷阱,捕捉器; v.使落入险境; (trap的第三人称单数和复数)
As soon as the tower went up with the node inside, human communication across the land went dark. 藏有能量晶石的塔高耸入云, 整个地球的人类交流 在该塔建成后从此中断。
As soon as:一…就; node:n.节点;结点;茎节;(根或枝上的)节; human communication:人际交往;
Octavia’s been after it for years, but try as she might, the defenses thwart her. 奥克塔维亚关注它好几年了, 但无论她怎么尝试, 都无法突破其防御系统。
thwart:vt.挫败; adj.横放的; n.划手座; v.横过; prep.横过;
In order to even get to the tower, the team will need a distraction . 艾斯克团队为到达塔下, 需要分散守卫的注意力。
distraction:n.注意力分散;消遣;心烦意乱;
Octavia has an idea: stir up the people through some well-intentioned vandalism . 奥克塔维亚有个主意: 通过一些善意的破坏公物行为, 来煽动人们(从而转移守卫视线)。
stir:v.搅拌;搅动;激发;搅和;n.搅拌;搅动;震动;搅和; well-intentioned:adj.好意的,好心的;出于善意的; vandalism:n.汪达尔人作风;故意毁坏文物的行为;破坏他人财产的行为;
The residents’ paintings are all squares that come in different sizes, all an odd number of pixels across. 居民画像是大小不一的正方形, 每个方向的像素数都是奇数。
odd:adj.古怪的;奇数的;n.奇数; pixels:n.像素(组成屏幕图像的最小独立元素);(pixel的复数)
Helper-bots pick up the finished portraits and hang them in public places for everyone to admire. 机器人助手收集画完的肖像, 并挂在公共场所供大家欣赏。
portraits:n.肖像;半身照;详细的描述;描绘;(portrait的复数)
There’s a slim margin of time when Hedge can access the paintings. 海吉只有极短的时间窗口 能接触到这些画,
slim:adj.苗条的;纤细的;单薄的;微薄的;n.(非洲用语)艾滋病;v.减肥; margin:n.边缘;利润,余裕;页边的空白;v.加边于;加旁注于;
If he were to deface each one with an X, the people would blame the helper-bots, creating just the distraction the team needs. 如果它在每幅画上涂个 X, 人们就会责怪机器人助手, 从而实现他们 分散机器人注意力的目的,
deface:vt.损伤外观,丑化;
If only it were so easy. 要是实现起来 也如此容易就好了,
his painting processor requires very specific instructions. 它的绘画处理器 需要非常具体的指令。
processor:n.[计]处理器;处理程序;加工者; specific:adj.特殊的,特定的;明确的;详细的;[药]具有特效的;n.特性;细节;特效药;
Treating the paintings as square grids , he can fill in one pixel, or little square, at a time. 它把这些画当作正方形网格, 一次只能填一个像素, 即只能填一个小正方形。
Treating:v.以…态度对待;把…看作;处理;讨论;(treat的现在分词) grids:n.[数]网格(grid的复数形式);栅格;
He can move forwards and make 90 degree turns over the canvas , but can’t move diagonally . 它在画布上可以向前移动, 也能进行 90 度旋转, 但不能斜着移动。
canvas:n.帆布;(帆布)画布;油画;vt.用帆布覆盖; diagonally:adv.对角地;斜对地;
How does Ethic program Hedge to paint an X over each portrait? 艾斯克如何编程, 才能让海吉在自画像上涂上 X 呢?
Pause now to figure it out for yourself. [ 可暂停播放自行解题 ]
Try drawing a square grid like this, and simulating Hedge’s path over it. 先画一个正方形网格,如图, 然后模拟海吉的涂画路径。
simulating:n.模拟;假装;
What patterns can you find to guide him? 如何指导海吉完成任务呢?
Pause now to figure it out for yourself. [ 按暂停自己解题 ]
The challenge here is to craft a set of instructions that will work for any square grid. 这里的挑战是如何设计指令组, 以适用任何大小的正方形网格。
Fortunately , one of the strengths of programming is the flexibility to solve not just one problem, but a whole class of them all at once. 幸运的是,编程的优点之一 就是其灵活性, 而是一次性解决一类问题。
Fortunately:adv.幸运地; flexibility:n.灵活性;弹性;适应性;
It often helps to start with one case, and work towards the general. 先从一个案例开始着手, 总有助于找到整体方案。
Let’s say we had this square. 我们假设正方形如图所示,
Hedge can measure the length of its sides and store that number as a variable . 海吉可测量其边长, 并保存为变量值。
variable:n.变量;可变因素;可变情况;adj.多变的;易变的;变化无常的;可更改的;
Now, what we need is a plan for how Hedge will paint an X, pixel by pixel. 现在,我们需要一个计划, 让海吉把像素逐个画上 X 。
There’s more than one right answer for how to do this; 实现方法不止一个,
First, what if Hedge went row by row, like a typewriter? 第一种,打字机模式, 让海吉一行一行地画。
what if:如果…怎么办?
If it’s a 9 pixel by 9 pixel painting, in the first row he’d paint, skip 7, and then paint again. 如果画像是 9 X 9 像素, 它先画第一行第一格, 跳过七格,然后画一格,
In the second row he’d skip the first, paint, skip 5, and paint. 第二行,他跳过第一格再画, 跳过五格再画,
And so on. 继续画下一行。
The pattern here is that for each row the pixels skipped at the beginning go up by one, and the pixels skipped in the middle go down by 2. 规则是,每行开始跳过的像素 +1, 中间跳过的像素 -2,
at the beginning:首先;从一开始;起初;从头开始;
Things get more complicated when Hedge reaches the center. 海吉画到中心点时, 情况变得更加复杂。
complicated:adj.复杂的;难懂的;v.使复杂化;(complicate的过去分词和过去式)
Here there’s a row with just one pixel painted. 这一行只画一个像素。
Then the whole thing reverses— the number of pixels skipped goes down by one each time on the left, and up by two each time in the middle. 然后,画的顺序就全反了 —— 左边跳过的像素数每行 -1, 每行中间跳过的像素数 +2。
Instructing Hedge to do this with a series of loops will work and is a perfectly fine solution . 海吉执行这组循环指令是可行的, 且是完美解决方案。
series:n.系列,连续;[电]串联;级数;丛书; loops:n.[计]循环(loop复数); v.使...成环,以圈结,以环连结(loop的第三人称单数形式); solution:n.解决方案;溶液;溶解;解答;
The main drawback is that this requires quite a bit of logic— knowing what to do in the middle, when to reverse the process, and exactly how to reverse it. 主要缺点是其中涉及的逻辑很多—— 每行中间做什么、何时反向操作, 以及如何精确反向操作。
drawback:n.缺点,不利条件;退税; reverse:n.反面; v.颠倒; adj.相反的;
So how might we approach this so that the logic remains consistent from start to finish? 那么,我们如何操作, 才能使逻辑始终一致呢?
approach:n.方法;路径;v.接近;建议;着手处理; logic:n.逻辑;逻辑学;逻辑性;adj.逻辑的; consistent:adj.始终如一的,一致的;坚持的;
The key insight is to look at a grid as a series of concentric squares. 关键是把网格 看作是一系列的同心正方形。
insight:n.洞察力;洞悉; concentric:adj.同轴的;同中心的;
Each square follows the same pattern— painted pixels in the corners, and unaltered pixels in between. 每个正方形遵循相同模式—— 只画四个角的像素, 其余像素不变。
unaltered:adj.不变的;未被改变的;照旧的;
So if we can figure out a way to paint one nested square, transition to the next, and repeat, we can paint them all. 因此,如果我们能找到 绘制一个嵌套正方形的方法, 即可应用到下一个,不断重复, 就能把它们全部绘制出来。
transition:n.过渡;转变;变革;变迁;v.经历转变过程;过渡;
Painting the outermost one is easy. 最外层正方形最容易绘制。
outermost:adj.最外面的;最远的;
Start in a corner and paint that pixel. 从一角开始,先画该角的像素。
If we call the length of the painting n, fly forward n minus 1 spaces. 假设画的长度为 n 像素, 就向前移动 n - 1 格,
minus:prep.减,减去;n.负号,减号;不足;负数;adj.减的;负的;
Paint another pixel, and turn right. 再画一个像素,然后右转。
Now do the whole thing again… and again. 接着再做一次循环操作 , 接着再做一次,
Now move forward one less space, turn right, fly forward once, and Hedge will be in the next concentric square and ready to repeat the whole process. 现在向前少移动一格, 右转,再向前移动一格, 海吉正好位于 下个同心正方形一角, 即可重复下一个循环过程。
Each square is n minus 2 pixels smaller than the last in length and width , and we can follow this spiral pattern all the way to the center with a loop and a variable that tracks how far Hedge should fly. 每个正方形的长宽 都比上一个少 n - 2 像素, 继续该螺旋模式,
width:n.宽度;广度;某一宽度的材料;(游泳池两长边之间的)池宽; spiral:n.螺旋;旋涡;螺旋形之物;adj.螺旋形的;v.使成螺旋形;vi.盘旋;螺旋形上升; tracks:n.小道;足迹;车辙;轨道;v.追踪;跟踪;(track的第三人称单数和复数)
Is one of these methods better than the other? 两种方式哪种更优呢?
It really depends on what you value. 这取决于你的侧重点。
The strength of the spiral is the simplicity of finding a pattern and reusing the same logic from start to finish. 螺旋循环的优点在于, 它简单地找到一个模式, 并从头到尾循序相同逻辑。
simplicity:n.朴素;简易;天真;愚蠢;
The advantage of the typewriter approach is that it’s a more generalized solution, meaning it can be adapted much more simply to fill in any pattern. 打字机方法的优点在于, 它是一个更通用的解决方案, 即它容易适应任何模式。
advantage:n.有利条件:优势:优点: generalized:adj.广义的,普遍的; v.推广(generalize的过去分词); adapted:adj.适于…的; v.使适应,使适合; (adapt的过去分词和过去式)
For Ethic’s sake , either will do just fine. 对艾斯克来说,哪种都能达成目的。
sake:n.目的;利益;理由;日本米酒;
So here’s what happens. 所以结果是这样的,
Hedge rapidly defaces all of the portraits. 海吉很快弄脏了所有的肖像,
defaces:vt.损伤外观,丑化;
And within moments cries of anguish break out all over the forest. 不一会儿, 痛苦的哭声响彻整个森林。
anguish:n.痛苦;苦恼;v.使极度痛苦;感到极度的痛苦;
The garrison guarding the tower abandon their posts to calm the agitated people, and Ethic, Hedge, and Octavia slip through— and nearly slip into the depths of the gorge standing between them and the tower. 守卫塔的守卫们 离开了他们的岗位, 以安抚骚动的人们, 艾斯克、海吉和奥克塔维亚 悄悄穿了过去 —— 差一点掉进幽幽深谷, 那位于他们和塔之间的万丈峡谷。
agitated:adj.激动的; v.搅动; (agitate的过去分词和过去式) slip:v.溜;下降;滑落;n.纸条;衬裙; gorge:n.峡谷;胃;暴食;咽喉;障碍物;vt.使吃饱;吞下;使扩张;vi.拚命吃;狼吞虎咽;