-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Janice H. #13
base: master
Are you sure you want to change the base?
Janice H. #13
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, the reason your code isn't working is that you add each node to the queue regardless of the order you encounter the nodes. I think you should only add them to the queue if the queue is empty and you haven't reached them yet. You can also take a look at my solution branch on the repo as well now.
|
||
while !graph_queue.empty? | ||
current = graph_queue.shift | ||
if !searched.include?(current) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using a hash with the key being the node and the color being the value. Then you can do unless searched[current].nil?
dislikes.each_with_index { |enemies, dog| | ||
graph_queue << dog | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding each node to the Queue in the beginning, maybe make that while loop below do something like this:
dislikes.each_with_index do |enemies, dog|
unless searched[dog] # make searched a hash
graph_queue << dog
current_color = # whatever starting color you're on
while !graph_queue.empty?
# Then your code continues with your while loop
Can't get that darn test 4! I know it's because when a node is neither color it defaults to one, so those ones are ending up with the same color, which later isn't allowed. Hmm.