fellowship 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fellowship.rb +45 -0
- data/lib/fellowship/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 22014485d2847bced85cb93e1d76531bb3845fbcb7b480092c78c8a57a46832d
|
|
4
|
+
data.tar.gz: 5135952eff7f19777f7c853221d8e61ffb6928e861348657a6597b2cff4ea6f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ac118f16ab04a5fdf896058b1771241b93e30afd1cd2bd331e3b6a2a4e69c43ee25204d26e3396dcfc978d8adf796d4f43b2c65c14a32cabd33983d8ab0c931
|
|
7
|
+
data.tar.gz: 0e801214de8f05ffdb7946a1b88d3bec62b03c4e612b79ed410c7f44b85cf457dfd594ba609d5dca038ebb9406aade24e2047548052bea64fc07848082ee14f5
|
data/lib/fellowship.rb
CHANGED
|
@@ -56,5 +56,50 @@ module Fellowship
|
|
|
56
56
|
end
|
|
57
57
|
return array_of_hashes
|
|
58
58
|
end
|
|
59
|
+
|
|
60
|
+
def self.find_route(start_id,end_id,segments,endpoint1, endpoint2)
|
|
61
|
+
possible_routes = []
|
|
62
|
+
directions = []
|
|
63
|
+
starts = segments.select{ | segment | segment[endpoint1] == start_id || segment[endpoint2] == start_id }
|
|
64
|
+
starts.each do |start|
|
|
65
|
+
if start[endpoint1] == start_id
|
|
66
|
+
first_tail = start[endpoint2]
|
|
67
|
+
else
|
|
68
|
+
first_tail = start[endpoint1]
|
|
69
|
+
end
|
|
70
|
+
if first_tail == end_id
|
|
71
|
+
return {route: [start.id], tail: first_tail}
|
|
72
|
+
end
|
|
73
|
+
possible_routes << {route: [start.id], tail: first_tail}
|
|
74
|
+
end
|
|
75
|
+
route_achieved = false
|
|
76
|
+
while possible_routes != []
|
|
77
|
+
new_possible_routes = []
|
|
78
|
+
possible_routes.each do |curr_route|
|
|
79
|
+
nexts = segments.select{ | segment | segment[endpoint1] == curr_route[:tail] || segment[endpoint2] == curr_route[:tail] }
|
|
80
|
+
nexts.each do |next_step|
|
|
81
|
+
if next_step[endpoint1] === curr_route[:tail]
|
|
82
|
+
next_tail = next_step[endpoint2]
|
|
83
|
+
else
|
|
84
|
+
next_tail = next_step[endpoint1]
|
|
85
|
+
end
|
|
86
|
+
if next_tail == end_id
|
|
87
|
+
route_achieved = true
|
|
88
|
+
end
|
|
89
|
+
if !curr_route[:route].index(next_step.id) || curr_route[:route].index(next_step.id) < 0
|
|
90
|
+
updated_route = {route: curr_route[:route] << next_step.id, tail: next_tail}
|
|
91
|
+
if route_achieved == true
|
|
92
|
+
return updated_route
|
|
93
|
+
else
|
|
94
|
+
new_possible_routes << updated_route
|
|
95
|
+
curr_route[:route] = curr_route[:route][0..-2]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
possible_routes = new_possible_routes
|
|
101
|
+
end
|
|
102
|
+
return "No route found."
|
|
103
|
+
end
|
|
59
104
|
end
|
|
60
105
|
end
|
data/lib/fellowship/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fellowship
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- joshsarna
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-03-
|
|
11
|
+
date: 2019-03-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|