Can you solve the risky disk riddle James Tanton

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?

Pause here to figure it out for yourself.
Answer in 3

Answer in 2

Answer in 1

The setting is a big clue
for one solution.

Using binary code— the base two
numbering system that only uses 1s and 0s—

we can represent each of the 4 disks
with a 2-bit binary number

ranging from 00 for zero
to 11 for three.

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.

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.

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?

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.

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.

Turning switch 11 on gives us 110
by standard binary addition.

But we don’t really want
three digit numbers.

So what if— to keep the result
a two digit number—

we break the rules a bit
and let this sum equal 22.

That’s not a binary number,
but if we regard 2s as the same as 0s,

that does indicate the correct disk.

So this suggests a strategy:

look at the sum of all the lighted disks
we see,

regarding 2s as 0s.

If it’s already the correct result,
flip 00,

and if not, find the switch that will
make the sum correct.

You can see for yourself that any
starting configuration

can sum to any number from 00 to 11
with a flip of a switch.

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.

And that’s why we can say that 2 and 0,
both even numbers,

can be treated as equivalents.

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.

What’s incredible about this solution
is that it works for any mainframe

whose disks are a power of two.

With 64 you could turn each activated disk
into a 6-bit binary number

and sum the 1s in each column,

regarding any even sum as the same as 0
and any odd sum as 1.

1,048,576 disks would be daunting,
but entirely doable.

Luckily, your mainframe is much smaller.

You make the valiant sacrifice
and your team rushes in,

destroying the corruption
and freeing the system.

您的防病毒小组正面临着
一种特别虐待狂

的恶意代码
,它劫持了您的大型机。

你从其他受感染的系统中学到的东西
——就在它们变黑之前——

是它喜欢
以一种非常奇特的方式玩弄防病毒代理。

它损坏
了运行您的大型机的 4 个磁盘之一,

由显示
哪些打开和哪些关闭的灯表示。

然后它会选择
防病毒小组的一名成员——这就是你

——并将他们带入大型机。

它告诉他们哪个磁盘损坏,

允许代理
打开或关闭单个磁盘,

然后立即取消代理。

您的小队可以进行全面攻击
以闯入大型机

并在一个磁盘
被消灭之前摧毁它们。

如果他们破坏了损坏的
,恶意软件将被击败。

任何其他人,病毒将
清除整个系统。

灯只
在主机内可见,

所以在你到达那里之前你不会知道
哪些灯亮着(如果有的话)。

您如何通过单个操作来传达

4 个磁盘中的哪一个
已损坏?

在这里停下来自己弄清楚。
回答 3

回答 2

回答

1 设置是
一个解决方案的重要线索。

使用二进制代码(
仅使用 1 和 0 的基二编号系统),

我们可以用 2 位二进制数表示 4 个磁盘中的每一个,

范围从 00 表示零
到 11 表示三个。

我们现在正在寻找的是
某种数学运算

,它可以将点亮的磁盘作为输入,
并将损坏的磁盘作为输出。

让我们考虑一种可能性。

说损坏的盘就是这个盘,

进来的时候,灯都没亮。

您可以打开 11
以指示该磁盘。

好吧,如果你进来了
,11 已经开始了怎么办?

你必须切换一盏灯。

哪个看起来最
无害?

可能是 00
,如果将 00 和 11 相加,

你仍然会得到 11。

所以,关键是要考虑
二进制数

的加法,点亮磁盘的总和
传达损坏的磁盘编号。

这很有效,直到我们
从不同的假设开始。

如果 00 是损坏的磁盘,
并且 01 和 10 处于打开状态怎么办?

在这里,点亮的磁盘的总和为 11。

但我们需要通过拨动一个开关将其更改为
总和 00。

我们有四个选项:
打开开关 00 给我们 11。

关闭 01 让我们回到 10

,关闭 10 给我们 01。

这些都不起作用。

打开开关 11
通过标准二进制加法得到 110。

但我们并不真正想要
三位数字。

那么如果——为了将结果保持
为两位数——

我们稍微打破规则
,让这个和等于 22。

这不是二进制数,
但如果我们认为 2 和 0 相同,

那确实表明了正确的磁盘。

所以这提出了一个策略:

查看我们看到的所有发光圆盘的总和

将 2 视为 0。

如果它已经是正确的结果,则
翻转 00

,如果不是,则找到
使总和正确的开关。

您可以亲眼看到,只需轻按一下开关,任何
起始配置

都可以求和为 00 到 11 之间的任何数字

这样做的原因与
称为奇偶校验的概念有关。

奇偶校验告诉您给定值
是偶数还是奇数。

在这种情况下,
我们正在考虑其奇偶校验的值是二进制和的

每个数字位置中的 1 的数量

这就是为什么我们可以说 2 和 0
都是偶数,

可以被视为等价物。

通过添加或减去
00、01、10 或 11,

我们可以更改其中一个、
两个或两个数字的奇偶性,

并创建我们想要的磁盘编号。

这个解决方案令人难以置信的
是,它适用于任何

磁盘为 2 次方的大型机。

使用 64,您可以将每个激活的磁盘
转换为 6 位二进制数,

并将每列中的 1 相加,

将任何偶数和视为 0
,将任何奇数和视为

1。1,048,576 个磁盘将令人生畏,
但完全可行。

幸运的是,您的大型机要小得多。

你做出了英勇的牺牲
,你的团队冲了进来,

摧毁了腐败
并释放了系统。