Các Bot Lò / Suy Nghĩ Như Một Coder, Ep 3

The Furnace Bots | Think Like A Coder, Ep 3
play-sharp-fill

The Furnace Bots | Think Like A Coder, Ep 3

 
Ethic and her robot Hedge agree to help the resistance leader, Adila, sabotage the art-incinerating furnace-bots. In exchange, Adila promises to lead them to the first object of Ethic’s quest, an artifact called the Node of Power. Years ago, there was just one furnace-bot. It had a 0 inside its furnace and an unknown, randomly generated serial number. Over time, the original self-replicated to produce more identical furnace-bots. Each child inherited the original’s unknown serial number within its furnace, and had a random, unique serial number of its own inscribed on its shell. The second generation of furnace- bots also self-replicated in the same way, always passing their own serial numbers to their offspring’s furnaces. This continued on for many generations. Today, each furnace-bot receives its orders from its parent. So if Ethic can find the original 0 bot and somehow change its instructions, she could take over the entire army, all at once. Adila has the perfect solution: a data crystal that she’s been carrying for years, waiting for the right moment to activate it. It contains a program designed to gain control of a bot and give it new instructions. But if it’s uploaded to any furnace- bot other than the original, the 0 bot will override the instructions and destroy the data crystal in the process. The feeding is just a few minutes away, and there’s only one chance to get this right. Fortunately, Hedge’s ability to store data can help. In programming, a piece of information gets stored in something called a variable. Variables are basically containers that hold onto numbers, words, or other values. How does Ethic program Hedge to find the original 0 bot as quickly as possible? Pause now to figure it out for yourself. Here’s a hint. Programs can be written to have as many variables as you need, but you can solve this problem with just one. Hedge can use it to store a serial number and replace it with a new one as often as he needs. Pause now to figure it out for yourself.
A key insight here is that Hedge doesn’t need to map out the entire
set of relationships to find the original furnace-bot. If, for example, he gets lucky and picks the original one right away, he’ll be done. But if he starts with any other bot, he can still find a path that leads straight back to the 0-bot by following a simple set of instructions. To help craft them, let’s first simplify the problem. Let’s say there were only three furnace-bots; a parent and two children, but you don’t know which is which. You could have Hedge pick one at random and look inside its furnace. Now, you know the family tree looks like this. If the number inside the furnace is a 0, you’ve found the parent. If not, then no matter which child you chose, it must have the parent’s serial number in its furnace. So in this scenario, you’re guaranteed to find the parent in one or two moves. In actuality, there are many furnace-bots, and you don’t know how many generations there are nor what the family tree looks like. But you don’t need to, because Hedge can just keep repeating the same sequence of actions until he gets to the original. How? With a loop. Hedge can pick any bot at random, look inside its furnace, and store that serial number as a variable. Then he’ll begin the following loop that will repeat until the stored variable equals 0, the furnace number of the original bot: 1. Find the bot whose shell serial number matches the stored number. 2. Look inside its furnace. 3. Store that new number, overwriting the old one. Once the loop ends, we’ll know that Hedge has found the 0 bot, so he should upload the control program. So here’s what happens: Hedge only takes 5 repetitions to find the original: robot 733 has the 0 in its furnace. In a blink of a mechanical eye, the program spreads through the entire army, and Adila takes control. She has the furnace-bots give off theatrical bouts of flame to hide the fact that they’re now secretly safe-guarding all of that artistic output. Now that Ethic’s delivered the furnace-bots, Adila honors her end of the deal. She leads Ethic and Hedge to the location of the first artifact, the Node of Power. There, one thing is immediately clear:
they’ll have to steal it.

think like a coder, coding, programming, variable, coding variables, how to code, learn to code, loops, coding loops, programming puzzles, girls who code, coding for beginners, coding projects, ted ed series, ted ed coding, computer science, education, ethic, hedge, robots, animation, code.org, coding lessons, TED, TED-Ed, TED Ed, Teded, Ted Education, tlac, tlac episode 1, alex rosenthal, kozmonot animation studios

Hide picture