Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Janice H. #13

wants to merge 3 commits into from

Conversation

jaitch
Copy link

@jaitch jaitch commented Apr 7, 2020

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.

Copy link

@CheezItMan CheezItMan left a 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)

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?

Comment on lines +12 to +14
dislikes.each_with_index { |enemies, dog|
graph_queue << dog
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants