# Bender - Episode 1 - Puzzle discussion

#83

I think you just need to rethink this you just got confused by numbers or spaces or I donât know.
The test is correct, good luck!

#84

I hope someoneâs still reading these, but can anyone explain WHY this case is tricky? I feed it into my algorithm and it posts a single move to the East and stops, yet the algorithm STILL wonât pass the first validation test. I have no clue why and without feedback as to WHY the code is failing, I canât debug it.

#86

Maybe make sure your algorithm can solve single step solutions in all four directions?

#87

I actually just found my bug. I had an inversion in places that allowed it to work with the test cases. Took forever to track it down.

#88

Congrats on solving it! I had a hard time with it, but was really proud when I solved it.

#89

Hi,
This puzzle is advertised as 130 XP. I have 100% score, yet Iâve got 100 XP.
There are 2 achievements which both give 50 XP. Where is this extra 30 XP?
Thanks.

#90

Well spotted, Iâll look into it.

Edit: Problem Solved

#91

I have managed to pass all 11 test cases, but I am dead stuck with multiple loops. Could you tell me if there are flaws in my logic:

Basically, whenever Bender moves, I record his new position, states and direction in a separate Array. Before each move is recorded to this Array, I cross-check current position, state and direction of a Bender with the Array of previously visited places(position, state, direction). If there is a match, I take it for a loop. It works fine for a single loop, but it fails in multiple loops test. Can you share you thoughts, where is the flaw in my logic?

Thanks

#92

I have managed to pass all 11 test cases, but I am dead stuck with multiple loops. Could you tell me if there are flaws in my logic:

Basically, whenever Bender moves, I record his new position, states and direction in a separate Array. Before each move is recorded to this Array, I cross-check current position, state and direction of a Bender with the Array of previously visited places(position, state, direction). If there is a match, I take it for a loop. It works fine for a single loop, but it fails in multiple loops test. Can you share you thoughts, where is the flaw in my logic?

Thanks

#93

I am not sure if position, state and direction are enough, as you may have changed the map by breaking obstacles, and so even if you get back on the same position, state and direction you may not be in a infinite loop as you may pass through an obstacle you destroyed before.
You may add the number of obstacles present on the map in your array.
I canât be 100% positive it will work as I bypassed this issue by counting the number of movement Bender made and when the number is too big I assumed I was in a loop.

#94

Thanks, I will think about this, but I personally think that adding the obstacles isnât very important (at least thatâs the first thought). You see, when Bender in Breaker mode walks over âXâ, I update the âmapâ, by replacing âXâ with " ", because the instruction says that the âXâ is destroyed permanently. So even if I count obstacles, it is the same as if I was counting any other cell in the map. Bender will walk over it again if it is a loop, probably with the same states. This is my impression.

Or did you mean something else by âadd the number of obstacles in your Arrayâ ?

#95

And letâs not forget - I do get the âLoopâ test correctly, the identification of a single loop works well. I only have problem with multiple loops, which makes me think that we need to assume that some if some amount of moves is used and â\$â has not been reached, then we should consider it a multiple loop. But it doesnât feel like the right decision

#96

Are you checking for both his inverted state, and his breaker state?

#97

To detect this, I clear out my history array any time I break an obstacle.

#98

mixolyde way is good too.

What I meant by âyour arrayâ was the array where you save the precedent places bender has been in which you attach the position the state and direction of bender, and I think you should add the number of obstacles you had on the map at this moment to those previous parameters.
Because for instance you may encounter an obstacle while moving from north to south and have to go away but after you may break it by moving from east to west with a beer state. Then if you are moving again from north to south toward the box, your program without a record of the number of obstacle associated with your position direction and status would assume you are in a loop although you may pass through the destroyed object.

I have to admit that counting the number of move was not a really beautiful solution, it is not really robust but it worked on the validators

#99

Some way to track the state of the map is as important as anything else. Remember, to detect a loop, you need to know the state of the ENTIRE finite state machine, not just the state of Bender. The map is part of that FSM, so if the map has changed, then even if Bender returns to the same coordinates with the same breaker and inversion state, the MACHINE will be in a different state and a loop canât be assumed.

Mixolydeâs solution is nice and elegant. The idea is to know if Benderâs state has ever repeated while the map is in its current configuration.

#100

Bonjour,

jâarrive Ă  passer tous les tests mais aprĂšs soumission, seul le 1 et le 11 sont ok, les autres Ă©chouent. Une idĂ©e ? Je peux Ă©galement poster le code (bash)

#101

So I pass every test except the last one, where I am not getting LOOP outputs just wrong outputs.
When I submit I pass every test except the last one plus âbreaker modeâ. Can anyone tell me what I may be doing wrong since I somehow get home in the last test, somehow pass the main breaker mode, however not the Submit edition of the âbreaker modeâ.

#102

Nice solution! I passed 100% now,

#103

Still having problems with the first validator. Iâve even tried having output âLOOPâ or just the one move in case of 12 squares (cause you really canât catch him in one step), without the 12 square validator that simple 3x4 outputs 2 moves. but no matter what i try, I canât get past 92%, I even have a showMap in the BenderMap class, so I can show "B"ender everywhere he moves. LOL itâs a true state machine,

`moves[]; index = 0; while(map.hasNext()) { moves[index] = map.getNext(); //save moves index++; map.showMap(); }`

Fixed it. Iâm mildly dyslexic, so I was testing if next spot is exit no more moves. I changed it to test this spot only for exit and boom, no need for 12 square check, cause big map all Xâs just 2 spots @ and \$ is same as 3X4, Works perfect.