Created
May 27, 2011 23:32
-
-
Save basicxman/996400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ap' | |
| require 'tsort' | |
| $test_data = { | |
| :b => :a, | |
| :c => :a, | |
| :d => :b, | |
| :e => :b, | |
| :f => :b, | |
| :g => :c, | |
| :h => :c, | |
| :i => :c, | |
| :z => :h, | |
| :x => :h, | |
| :y => :h | |
| } | |
| class Hash | |
| include TSort | |
| alias tsort_each_node each_key | |
| def tsort_each_child(node, &block) | |
| fetch(node).each(&block) | |
| end | |
| end | |
| $test_data.strongly_connected_components | |
| abort | |
| $global_hash = {} | |
| def fill_global_hash | |
| $test_data.each do |parent, child| | |
| $global_hash[child] ||= [] | |
| $global_hash[child] << parent | |
| end | |
| end | |
| =begin | |
| def resolve(root) | |
| temp = {} | |
| puts $global_hash[root] | |
| $global_hash[root].each do |key| | |
| if $global_hash[key].nil? | |
| temp[key] = :done | |
| else | |
| temp[key] = resolve(key) | |
| end | |
| end | |
| temp | |
| end | |
| =end | |
| fill_global_hash | |
| ap $global_hash | |
| def find_trail(crumb, trail) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment