@@ -132,9 +132,12 @@ fn find_longest_path(
132132 }
133133 path. insert ( current) ;
134134
135- for ( next, additional_length) in condensed_graph. get ( & current) . unwrap ( ) {
136- stack. push ( ( * next, length + additional_length, path. clone ( ) ) ) ;
137- }
135+ condensed_graph. get ( & current) . unwrap ( )
136+ . iter ( )
137+ . filter ( |( next, _) | next != & current)
138+ . for_each ( |( next, additional_length) | {
139+ stack. push ( ( * next, length + additional_length, path. clone ( ) ) ) ;
140+ } ) ;
138141 }
139142
140143 best
@@ -177,7 +180,6 @@ fn walk_paths(current: &Coordinate, adjacent_strategy: &dyn Adjacent) -> Vec<(Co
177180 . collect ( ) ;
178181 let mut visited = HashSet :: from ( [ * current] ) ;
179182 let mut results = Vec :: new ( ) ;
180- let previous = current;
181183
182184 while let Some ( ( current, length) ) = stack. pop ( ) {
183185 if visited. contains ( & current) {
@@ -187,9 +189,7 @@ fn walk_paths(current: &Coordinate, adjacent_strategy: &dyn Adjacent) -> Vec<(Co
187189
188190 let adjacent = adjacent_strategy. get_adjacent ( & current) ;
189191 if adjacent. len ( ) != 2 {
190- if current != * previous {
191- results. push ( ( current, length) ) ;
192- }
192+ results. push ( ( current, length) ) ;
193193 continue ;
194194 }
195195
0 commit comments