Your antivirus squad is up against a particularly sadistic bit of malicious code that's hijacked your mainframe.
你的杀毒小队面对的是一个残暴且充满恶意的代码,它劫持了你的主机。
What you've learned from other infected systems -- right before they went dark -- is that it likes to toy with antivirus agents in a very peculiar way.
你从其他受侵害的系统中学到--就在它完全摧毁主机之前--是它喜欢和杀毒软件玩一种特殊的游戏。
It corrupts one of the 4 disks that run your mainframe, represented by lights showing which are on and which off.
它损坏了运行你主机的四个磁盘之一,以灯光表示磁盘的开关。
Then it selects one member of the antivirus squad -- this'll be you -- and brings them into the mainframe.
然后它会选择杀毒小队的一名成员--就是你--带入主机。
It tells them which disk it corrupted, allows the agent to switch a single disk on or off, then immediately de-rezzes the agent.
它告诉你损坏的磁盘是哪一个,允许你打开或关闭一个灯的开关,然后会立即消灭掉你。
Your squad can make an all-out attack to break into the mainframe and destroy one disk before they're wiped out.
你的团队可以闯入主机并在被消灭之前摧毁一张磁盘。
If they destroy the corrupted one, the malware will be defeated. Any others, and the virus will erase the entire system.
如果摧毁了被损坏的磁盘,那恶意软件就会被击败。如果摧毁任何其他一个,病毒将清空整个系统。
The lights are only visible within the mainframe, so you won't know until you get there which, if any, are on.
这些灯仅在主机内可见,因此在你到达那之前不会知道亮灯的是哪个(如果有的话)。
How can you communicate, with your single action, which of the 4 disks has been corrupted?
你将怎么用单一一个动作将信息传达给你的团队,四个磁盘中的哪一个是被损坏的呢?
The setting is a big clue for one solution. Using binary code -- the base two numbering system that only uses 1s and 0s
这个系统设置为解决方案提供了明显线索。运用二进制编码--仅用0和1的编码系统
we can represent each of the 4 disks with a 2-bit binary number ranging from 00 for zero to 11 for three.
我们可以用一个二进制编码来对磁盘进行编号,从00代表0,到11代表3。
What we're looking for now is some sort of mathematical operation that can take the lit disks as input, and give the corrupted disk as an output.
现在我们要做的就是一些能够通过亮灯作为输入,损坏灯泡作为输出的数学运算。
Let's consider one possibility. Say that the corrupted disk was this one, and when you come in, no lights are on.
我们来考虑一种可能性。假设这个是被损坏的磁盘,并且当你进入主机时,没有磁盘是亮灯的。
You could turn 11 on to indicate that disk. Okay, what if you came in and 11 was already on? You have to switch one light.
你可以将11的灯点亮来通知你的团队。好的,那么如果当你进入时11是亮灯的呢?你必须要操作一个开关。
Which seems like the most innocuous to change? Probably 00, in that if you were to add 00 and 11, you'd still get 11.
哪一个看起来像是最无关紧要的呢?可能是00,如果你用00加上11,你仍然得到11。
So maybe the key is to think of addition of binary numbers, with the sum of the lit disks communicating the corrupted disk number.
所以也许答案就是将二进制数相加,通过亮灯的磁盘的总和传递损坏磁盘的信息。
This works great, until we start with a different hypothetical. What if 00 was the corrupted disk, and 01 and 10 were on?
这非常好用,直到我们开始另一种假设。如果00是被损坏的磁盘,并且01和10是亮灯的呢?
Here, the sum of the lit disks is 11. But we need to change this to a sum of 00 with the flip of one switch.
这里,亮灯磁盘的总和是11。但是我们还需要操作开关一次将总和变成00。
We have four options: turning switch 00 on gives us 11. Turning 01 off takes us back to 10, and turning 10 off gives 01. None of those work.
我们有四种选择:点亮00得到11。关掉01得到10。和关掉10得到01。全部没有用。
Turning switch 11 on gives us 110 by standard binary addition. But we don't really want three digit numbers.
关掉11,通过二进制加法得到110。但是我们并不想要三位数字。
So what if -- to keep the result a two digit number -- we break the rules a bit and let this sum equal 22.
那么如果--只保留两位数字--我们稍稍打破规则让它得到22。
That's not a binary number, but if we regard 2s as the same as 0s, that does indicate the correct disk.
这不是一个二进制数字,但是如果我们将2看作0,这将会指向正确的磁盘。
So this suggests a strategy: look at the sum of all the lighted disks we see, regarding 2s as 0s.
所以这表明了一种策略:看亮灯磁盘的编号的总和,将2看作0。
If it's already the correct result, flip 00, and if not, find the switch that will make the sum correct.
如果它已经是正确的结果,开关00号磁盘,如果不是,找到那个能够让总和正确的磁盘。
You can see for yourself that any starting configuration can sum to any number from 00 to 11 with a flip of a switch.
你可以注意到任何初始情况都可以通过改动一次开关,用00和11加成任意总和。
The reason this works is related to a concept called parity. Parity tells you whether a given value is even or odd.
这个策略跟一个叫做奇偶校验的概念是相关的。奇偶校验会告诉你一个已知量是奇数还是偶数。
In this case, the values whose parity we're considering are the number of 1s in each digit place of our binary sums.
在我们的情况中,我们要奇偶校验的数是在每个位置上所有二进制数中1的总和。
And that's why we can say that 2 and 0, both even numbers, can be treated as equivalents.
这是为什么我们可以说2和0,都是偶数,可以被看作是相同的。
By adding or subtracting 00, 01, 10, or 11, we can change the parity of either, both, or neither digit, and create the disk number we want.
通过相加或相减00、01、10或11,我们可以改变任一、全部,或没有位置的奇偶性,得到我们想要的磁盘编码。
What's incredible about this solution is that it works for any mainframe whose disks are a power of two.
令人惊叹的是这个方法在任何主机中都适用,只要它的磁盘是2的幂。
With 64 you could turn each activated disk into a 6-bit binary number and sum the 1s in each column,
如果64次幂,你可以将每一个磁盘编码为一个6位二进制数并且相加每个位置上的1,
regarding any even sum as the same as 0 and any odd sum as 1.
然后将任意偶数看作0,任意奇数看作1。
1,048,576 disks would be daunting, but entirely doable. Luckily, your mainframe is much smaller.
1048576磁盘听起来令人生畏,但完全可行。幸运的是,你的主机小多了。
You make the valiant sacrifice and your team rushes in, destroying the corruption and freeing the system.
你英勇地牺牲了,然后你的团队冲进来,摧毁了被损坏的磁盘并挽救了系统。