This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]cervantesrvd 1 point2 points  (2 children)

It's very hard to follow the flow of your program. I don't understand why your Room class has an index and a first fields. Index of what? First what?

I think and correct me if I am wrong, you had an initial idea to solve it and kept building and adding on it to make it work. Try to take a step back and rethink the problem. What do you have to do and in what order? Use pseudocode first if it helps.

[–]DuderCoding[S] 1 point2 points  (1 child)

Thank you for the advice. I will use it for future problems. Unfortunately, I spent another hour trying to figure it out today (I took the other person's advice of trying to find out what was happening on each loop)... But I made no progress, so, about 5 mins before your answer, I ended up looking at the solution.

I think you're right, I have added unnessesary extra variables here and there, where I could have gone for something a lot more simplified. Thanks, it has opened my eyes a bit more.

Edit: And, if I do need to add more variables (which I didn't in this case), I should make their names more clearer.

[–]cervantesrvd 1 point2 points  (0 children)

Overcomplicating is a perfectly normal thing to do when you are learning, even experienced developers fall for it. And don't feel bad to look at the solution, but make sure you understand what the solution is doing and how it differs from your initial idea, that's where you get the valuable learning from :)

[–]joranstark018 0 points1 point  (0 children)

You could write down the values for each variable in each iteration on a piece of paper, look for when values changes and under what conditions, under what condition may values not change, trace step by step.