# Blunder - Episode 1 - Puzzle discussion

Who was the game â€śBender, a depressed robot?â€ť Map â€śBroken wall?â€ť
[18:39] In my opinion there is a mistake.

Hi,
What do you mean by â€śwho was the game â€śBender, a depressed robot?â€ť Map â€śBroken wall?â€ťâ€ť?
If youâ€™re saying that the test is wrong, normally it shouldnâ€™t, and I can pass this test with my code.
Can you provide more informations if youâ€™re doubting the validity of this test (programming language, maybe explaining quickly without spoil the solution (do not include code)) ?

All right. Itâ€™s my fault. Misunderstood the task.
I do not know much English, and the translator is not always the correct translation.

Sorry â€¦

Good luck for solving this task !

Keep coding!

2 Likes

Ok, i solved this. Bender got all but two suicide booths. I hope he met Fry there!

â€śBite my shiny metal ass, meatbags!!!â€ť Â© Bender

Please donâ€™t get offended, iâ€™m a big fan of Futurama and itâ€™s just a quote:)

Incremental way of building functionality doesnâ€™t work for me at all - i have a lot of smelling code in the end. Write code that passes first test case, then write code that will pass second test case, but donâ€™t refactor. Well, thatâ€™s my curiosity on whatâ€™s ahead

The only useful thing i wrote for this challnge is bidirectional dictionary type. Itâ€™s a list of pairs, and you can use it as dictionary by either key (returning a value) or by value (returning a key). I needed those to keep two-way relation between char (â€™#X@\$SEWNTIBâ€™) and a enum type representing a tile on a map.

I used very simple solution for loops - if tile was already visited for 5 times (i know, i know), itâ€™s a loop, do nothing. Probably itâ€™s the reason i get 100% but puzzle page isnâ€™t updated?
UPD, itâ€™s not, i was rated 100% after some time.

Thanks Codingame, now i know for sure that

I did so : if bender goes on a cell with the same status (Inverted / Breakermode) and direction than previouly, it is a loop. Of course if the map changes (wall break), you have to clear the traces.

6 Likes

I canâ€™t get 100%.
In tests i passed all 12 tests, but when i click on â€śSubmitâ€ť - i get only 91% without â€śLOOPâ€ť.
Why it happen?

As we donâ€™t know what is your problem, is it hard to say, but if you canâ€™t pass â€śLOOPâ€ť that mean that you didnâ€™t handle LOOP case efficiently. As said numerous times: submit tests cases slightly differs from normal tests cases. Try implementing one of the idea spoken above to check efficiently for a loop case.

I finally got 100%.
But got it in very weird way: I commented part of code where bender must turn NORTH->WEST(in normal mode) and EAST->SOUTH(in inverse mode).
)))
Maybe i did not understand something in this quest.

You intrigued me.

How you then pass tests where there are inverters / NSWE modifiers?O_o

1 Like

Of course if Bender saw modifiers(NSWE) he will turn.
I commented code where Bender saw wall(#,X) and must turn NORTH->WEST(in normal mode) and EAST->SOUTH(in inverse mode).

I still donâ€™t get it.
What does bender do when he sees a wall then?

Letâ€™s not flood here, congrats on 100%

1 Like

Canâ€™t we see the log of final tests ?
My program passes all the development tests. When I submit it passes all the final tests except the first (the simple one).
I canâ€™t see why !

I need a help. I can not solve LOOP (85 pts) test case on submition. Loop test case from basic test I can pass.

Iâ€™m not sure what Iâ€™m doing wrong. The main idea how I detect loops is something like:

• I have matrix [C, L] of Lists of Bender states when he reach some position (Y, X)
c# something like List[,]
• Bender state is defined by four parametres Direction, HasBeer, Inverted and BrokenValsCounter (how many walls Bender crashed while getting into position because path after can change depending if there is some space where used to be wall)
• When I try to move to some new position I calculate next bender state and check if he already was in that position in that state. If he was, I try next move depending on other parameters (inverted, etc)
â€“ if Bender can not move in current position (all around him are walls, invalid positions, already visited [with same state] fields, etc) I declare Bender is in loop and exit program

I can not spot where I make mistake. Can someone give me a little hint or something?

1 Like

Your representation of a state is correct and you should be able to detect a LOOP. Are you sure to store all the previous states for a given position (there could be more than 1 previous state for a position) ?

1 Like

Yes, that the whole point, I can not see what Iâ€™m doing wrong. Right now Iâ€™m thinking I have some stupid mistake but not sure how other cases works well.

this structure I am using for states (C#):

List[,] mapState = new List[L,C];

Check if possible and update func:

``````(state, p) => {
Â                List<BenderState> bss = mapState[p.Y,p.X];Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  var rv = bss.Exists(x => x.IsSameAs(state));
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  if (!rv) {
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  bss.Add(state.Clone());
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  return true;
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  }
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  return false;
}
``````

IsSameStateAs (in blenderState class)

``````public bool IsSameAs(BenderState other) {
Â Â Â Â Â Â Â Â Â Â Â  return HasBeer == other.HasBeer && Inverted == other.Inverted &&
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Dir == other.Dir && BrokenValsCounter == other.BrokenValsCounter;
}
``````

Clone method and constructor:

``````Â public BenderState Clone() {
Â Â Â Â Â Â Â Â Â Â Â  return new BenderState(this);
}

public BenderState(bool hasBeer, bool inverted, Direction dir) {
Â Â Â Â Â Â Â Â Â Â Â  HasBeer = hasBeer;
Â Â Â Â Â Â Â Â Â Â Â  Inverted = inverted;
Â Â Â Â Â Â Â Â Â Â Â  Dir = dir;
Â Â Â Â Â Â Â Â Â Â Â  BrokenValsCounter = 0;
Â Â Â Â Â Â Â  }

public void From(BenderState other) {
Â Â Â Â Â Â Â Â Â Â Â  HasBeer = other.HasBeer;
Â Â Â Â Â Â Â Â Â Â Â  Inverted = other.Inverted;
Â Â Â Â Â Â Â Â Â Â Â  Dir = other.Dir;
Â Â Â Â Â Â Â Â Â Â Â  BrokenValsCounter = other.BrokenValsCounter;
Â Â Â Â Â Â Â  }
public BenderState(BenderState other) {
Â Â Â Â Â Â Â Â Â Â Â  From(other);
Â Â Â Â Â Â Â  }
Â Â Â Â Â Â Â
``````

Your code doesnâ€™t handle the following:

But I memorized List of states in one position, that is why Â List < BenderState > [,] mapState and not just BlenderState[,]. It is multidimensional array (L * C) of lists of bender states.
Maybe has beer. inverted, direction and how many walls did he brake are not the only properties that are important. Maybe some other?

I only used these properties in my code, and it was fine.
Can you paste your code in a pastebin (pastebin.com) with option â€śPaste Exposureâ€ť set to â€śunlistedâ€ť, then send the link to coders[at]codingame[dot]com?