# Bender - Episode 1 - Puzzle discussion

#129

Quote from puzzle:

The circuit inverters (I on map) produce a magnetic field which will reverse the direction priorities that Bender should choose when encountering an obstacle.

So it's obviously your second way of understand this. But be careful that Bender will keep this mode (inverted decisions) until he reaches another inverter.

#130

I'm passing all validation tests except for "All together" and I can't figure out why. What are the usual culprits when passing all the validation tests except "All together"?

#131

Hi,
Man, thats puzzle is great. I try to teach myself programing and I belive this is the first puzzle that tought me something beside simple coding. It made me think before I started to write code and after that it showed, that my thinking time was way to short!
It took me few hours to finish, I wonder how much time does it take on average.

#132

The thing is that even if you code the loop flag correctly, that is only if you pass the same location with the same direction, the multiple loop is tricky. In that level you pass the same point with the same direction more that 3 times. so for that level you have to make the loop flag come up only after more occurrences of the same location and direction. they meant INFINITELY after all...

#133

Direction and location are only 2 parts of Bender state. Is he drunk? Is he "inverted"? How many walls has he broken so far? You just need to keep track for all of this.
If bender passes some point for the second time and he is drunk as well as the last time and he moves in the same manner as last time AND he has not broken any new wall since the last time - you may assume that the loop is infinite.

#134

Hello,
I am hoping someone can help me. I can't find the bug in my code but there must be one (or many) because the code does not pass tests 11 and 12 (loops and multiple loops). It looks like the original position of Bender is never met because I never see my debug trace "cerr << DEBUG << endl" (it's C++). But I guess the loop is when you meet the original position of Bender. I pasted my code on PasteBin (for a day only). It's here https://pastebin.com/nNUThyHb
If anyone can help I would be very grateful, it's driving me crazy.
Marie

#135

I see know I was a bit optimistic in hoping someone would help me within a day so here is my code pasted for a month https://pastebin.com/zr5Vx20m

#136

A loop doesn't mean that you come back to the start '@'. It's when Bender return to a position (with the same state) twice.

#137

Thank you. So I should keep a log of Bender's positions, with his state ?

#138

Just wan't to share a couple of annoying bugs in my code in finding LOOPS.
First I made an array of "states" to see if I am at the same coordinates with same modes. A state looked like this string "YX(normalMode?)(beerMode?)"
This doesn't work for coordinates bigger than 10, since Y=1, X=11 is the same as Y=11, X=1 when concatenated. So I just added a space between.
The second bug was that when you remove "X" cell in Breaker Mode this doesn't work, so you should reset the array you use to check for repeating states.

Hope this saves you some time if someone's stuck on this for as long as I was

#139

I am having trouble with Breaker mode. My code isn't actualy 'breaking' the 'X' character (i.e. removing it from the map). I am working with javascript:

``````if(charAtNewPos === 'X' && bender.breaker){
map[newPos[0]][newPos[1]]  = '   ';  // **here i am trying to change the value 'X' on the next position on th map to empty string **/
printErr( map[newPos[0]][newPos[1]] ) /* but in this next line, printErr prints 'X' as if nothing changed *//}``````

i am working in javascript. this is a statement in the function that checks next position on a map. Map is a global variable.
I think it has to do something with the scope ... any help ???

#140

Does anyone have the map for the validator test 2 "Obstacles"?
I can pass all tests in the IDE and all other validator tests, I just don't get it...

#141

in javascript strings are immutable. So need to convert string to array of chars by split

#142

What's the difference between loop and Multiple loop cases? I detect loops in both of them. When I print "LOOP" in the single loop test case it works fine but when I print "LOOP" as my first response in the multiple loop test case the console says "SOUTH" is first from expected answers.

#143

The difference is whether Bender can reach \$ ultimately.

#144

So for the test #12 the "LOOP" is not a correct answer?

#145

No it isn't. You can click the button there (next to the word "Actions") to view all the test cases (not the validators) and the answers.

#146

That's handy Thanks

#147

I used a set of states to check for loops, but there's a different solution: since there are only 16 distinct states Bender can have (4 directions, 2 breaker modes, 2 priority modes), you can say that you found a loop once you visited the same cell more than 16 times (via pigeonhole principle). Don't forget to clear visit counters when you modify the map by breaking an obstacle.

#148

Hi, my bender’s solution can pass all the tests and vaidation tests except for the teleport validation one.
Can anyone tell me what this test is ?
My bender store his position, his previous position, his invert state and destroyer state…

Thanks