Skip to content

Instantly share code, notes, and snippets.

@ArionHardison
Created November 29, 2014 20:23
Show Gist options
  • Save ArionHardison/c68bb564fae05abcba59 to your computer and use it in GitHub Desktop.
Save ArionHardison/c68bb564fae05abcba59 to your computer and use it in GitHub Desktop.
# the graphs in this case are represented by their adjacency matrix (see below),
# where graph[i][j] == 1 if there is an edge between nodes
#todo - try and implement as breadth first or at least figure out which would be bettter
lbl = %w(Good OK Better Meh Worse Not_OK Bad)
graph = [0,1,1,0,0,1,0,0,0,1], # Good
[1,0,0,0,0,0,0,1,1,0],
[0,0,0,0,0,0,0,0,0,0],
[1,1,0,0,1,0,0,1,1,1],
[0,0,0,1,0,1,1,0,1,0],
[1,0,1,1,0,0,0,0,0,0],
[1,0,0,0,1,0,1,1,1,1] # Bad
def traverse(v)
edge = 0
while edge < graph.size
graph[v][edge] = 0
edge += 1
end
edge = 0
while edge < graph.size
if (edge != v and graph[edge][v] != 0)
traverse(edge)
end
edge += 1
end
end
6.times do |i|
traverse(i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment