The Train Heist | Think Like A Coder, Ep 4

The Train Heist | Think Like A Coder, Ep 4


Ethic, Hedge, and Adila, the leader
of the revolution, plot out how they can steal an artifact
called the Node of Power. It’s being used to run a heavily fortified
train that runs all around the country, providing supplies to settlements
and facilities. This armored behemoth
undergoes a complex and unpredictable unloading
procedure— a procedure which is displayed, in detail,
on a screen within the engine car. Right means the train will go one
car length forward, and left means the train will go the
same distance backwards. While unloading, the train frequently
moves back and forth, so a typical sequence
might look like this. Also within the engine car is a button
that can only be pressed once. When pressed, it lets down the force
field over the artifact for 10 seconds. The engine car is tiny
and designed for a robot. Of your team, only Hedge can fit. The members of the resistance have
positioned a crane over the train tracks that can pluck the artifact
once it’s exposed. They’ll know when to lower
the crane by sight. But the only way Hedge can determine
the train’s position and know when to lower
the force field is by analyzing the unloading procedure, because he’ll be inside
the windowless engine car. Hedge can’t program himself though, so
it’s up to Ethic to tell him what to do. The artifact is in the car 10
positions behind the one that’s directly under the
crane at the start. What instructions can Ethic give Hedge so that he hits the button
at just the right moment? Here’s a hint to get you started. The key to this problem, as with many
programming challenges, is to reframe the information in a way
that a computer can work with. A computer doesn’t know what a
train is, nor does it need to. It can, however, work with variables. Try making a variable that tracks
the train’s position. How will it change as the train moves? Let’s start by breaking this problem
into two objectives. The first is to know where the train will
be as it carries out its instructions. The second is to hit the button when
the train is in just the right position. For the first objective it’ll help to
think of the train as a big number line. Let’s make 0 the car with the node,
1 the car in front of it, and so on. That means car 10 is under
the crane at the start. When the train moves one car right,
car 9 is under the crane. So a right arrow can be
thought of as “subtract 1.” And when the train moves left from
there, 10 is back under the crane, making a left arrow the same as “add 1.” Let’s set our train position variable
to 10, since that’s where we start. We can now use a loop to read the
instructions one at a time, adding or subtracting as we go,
to track which car is under the crane. The nice thing about setting up
the variable this way is that it tells us how far the node
is from the crane. So as soon as the variable hits 0,
Hedge should hit the button. And here’s what happens. Ethic gets into position on the crane
while Hedge rushes off and slips into the engine car unnoticed,
just before the train lurches to life. It rolls 3 cars back. 1 forward,
another 4 back. Then so far forward Ethic loses track
before it reverses once more. When the artifact finally rolls into
position, Adila lowers the crane, hoping Ethic and Hedge got it right. At the last possible moment,
the force field sputters and falls. Ethic swoops in, and lifts the
Node of Power to freedom. When Ethic gives the node to
Hedge for safe keeping, something incredible happens. The artifact shimmers to life
with a vision of the past: When the crystal was unearthed,
no one could make the console inside work. The government put out a call for
people to try their luck with it, one at a time. Ethic loved to figure out what made
things tick, so she signed up. Within moments at the console,
something clicked into place, and she created her first robot. The government hired Ethic as
chief robotics engineer on the spot. Within a year her creations ran almost
every aspect of society, and the nation and its people thrived, no longer needing to toil in the
fields and factories. The vision ends, and Hedge detects
the second artifact in the 198forest, to the southeast. Luckily, the train is going there next, and has just enough reserve
fuel for the trip. Ethic and Hedge smuggle themselves aboard and find a hiding spot for the
long journey ahead.

100 Replies to “The Train Heist | Think Like A Coder, Ep 4”

  1. 6 episodes remain! Don't want to miss the action? Make sure to subscribe and turn on notifications! Whether you're a coder or not, this epic adventure is for you. See if you can rise to the challenge! New to the series? Start the journey from the beginning with episode 1: http://bit.ly/TLACEp1

  2. It was amazing!!! I am very excited to know what will happen next!!! I am waiting for the next episode eagerly!!! 😄😄😄

  3. A big thanks to TEd-Ed for presenting this wonderful and awesome series. I am a newbie in coding but this series keeps me motivated. Keep on this highly anticipated series. Thanks once again.

  4. Think like a coder, act like a thief
    Apparently you can’t use “beef stew” as a password.
    It’s not stroganoff.

  5. i didn t understand why a train could go backwords , and also i m not a native english speaker so it might be the reason why i didn t get it

  6. Important rule information not shown in the summary: The target is in the car 10 spaces behind the car under the crane

  7. I basically did the opposite, but I think it still works. Basically, 10 is the goal. Forward adds, backward subtracts.

  8. The animation and story line are "A++". . Kudos to kozmonot studio and TED-ed. Coding portrayed in such a manner will surely intrigue several potential coders.

  9. I call a hunch, the main character's name Ethic refers to computer ethics, the morals of right and wrong in computer science and its consequences if the programmer misuses his knowledge of the computers and programming.

  10. bolca Türk adı gördüm o yüzden Türkçe yazmak istedim belki video yapımcılarından gören olur. HARİKA OLMUŞ animasyon efsane güzel izlerken insan keşke film olsada izlesem diyor

  11. Today's challenge was not so hard…. how many of you actually coded the solution? … how may actually coded the problem?

  12. Algorithm(there are minor errors i think).

    1.start
    2.count=10
    3.if(arrow=right) goto step 4 else step 6
    4.count=count-1
    5.if count==0,press button else step 3.
    6.if(arrow=left) goto step 7 else go to step 3.
    7.count=count+1
    8.if count=0 goto step 9 else step 3.
    9.press the button
    10.abort
    11.stop

  13. So can anyone tell me if these are actually difficult or not, because I've never done any coding in my life but thus far I've solved them all within about a minute tops… Seriously thinking about maybe giving coding a try

  14. An excellent series! I love that it’s entry level and accessible to everyone, regardless of money or background. Additionally I can see this being taught in schools. Personally I watch every video as soon as I see it debut.

  15. I have a spidey sense for when think like a coder comes out… does that mean I’m Spider-Man? Or… Spider-Girl?

  16. this episode screams "convenience" like there is no tomorrow!
    "at the last moment, just enough" .. and now it's possible that Ethic which literally means morality … could be the entire future's architect/coder!
    Adela / the resistance leader and her arabic name with its meaning "justice" and for some reason she was designed indian.. should have figured this by now!
    i did not notice Ethic was wearing a midriff! she looks nice!

  17. I got this one, but I actually did it in reverse order. Instead of having the train car under the crane be 10 and count down to 0, I declared the current train car to be 0 and had Hedge wait to press the button until ten cars had passed – or in other words, I counted up on right arrows and down on left, starting at 0 and ending at 10. This does exactly the same thing as the in-video solution but reverses the numbering system.

  18. I’m pretty sure there will be flashbacks when Ethic and Hedge get the Node of Memory, and the Node of Creation. And if so, I can’t wait to see what the flashback will be.

  19. why not program a tracker, if crane and tracker device are both true, hage can press the button. i'm just doing this lazy way because the robot can do anything in this series and i have the means to build a device (has it on her arm). Also this can also be super easy made by just pressing the button which will make Hage press the button. You shouldent risk something when you can manually do it.

  20. Before seeing the solution:

    Let’s assume that the next arrow can be represented by the variable nextarrow, and that nextarrow is only assigned a value for a single loop cycle.

    Carsoffset = 0

    while true:
    if nextarrow.direction == “right”:
    Carsoffset -= 1
    else if nextarrow.direction == “left”:
    Carsoffset += 1

    if Carsoffset == 10:
    Button.push()
    break

    Edit: nice I got it

  21. Great story and animation as always. But honestly, I am slightly disappointed about the fact that no new concept is covered in the video.

    There are 6 episodes left. Let’s predict what concept will be covered next.
    5. Array
    6. LinkedList
    7. Recursion
    8. Sort
    9. BinarySearch
    10. Graph/Tree
    Hopefully I can get at least a few guesses correct.

  22. Have the car with the artifact be 0 and the car after the engine be 10 and count down, i guess ort soemthing. I just love the train

  23. What if Hedge was Ethic’s attempt at an AI, but Hedge tried to program with her. Because he can’t create programs, the program he tried to make malfunctioned, causing Ethic and Hedge to be in the prison at the start of the series.

  24. I expected this to be a difficult problem.
    As soon as I heard the questions, I was like… addition and subtraction? Really?… -_-

  25. All of the episodes are quite interesting and easy to understand . I really appreciate the efforts by the complete team behind this !

  26. Any computer science student here who immediately thought of the standard Turing Machine when it said the train can move left or right any number of times?

  27. Loved it
    Awesome way to explain coding.
    I am also a programming teacher and always searching for stories to teach programming but this is the best
    Hats off
    ❤️❤️❤️❤️

  28. oh btw here's what the code would look like if it was Lua

    nodePos = -10
    while nodePos ~= 0 do
    if trainMoveLeft then
    nodePos = nodePos + 1
    elseif trainMoveRight then
    nodePos = nodePos + 1
    elseif nodePos = 0 then
    pressButton()
    end
    end

    I seriously have nothing else to do

  29. Because the way you solve the problems there with scartch like "programming" when you litterally have a robot with top tier AI.
    I care only about the thiccness of Ethic!

  30. Kudos TED ED. Sure i woild've praised you better, but *lazy thoughts roll over*. Yeah but, should've at least bid adeu to ADILA. Hmmm. Well just read the previous comments and please take them from my side… please. Again
    Kudos TED ED.

Leave a Reply

Your email address will not be published. Required fields are marked *