I have a function that is somewhat similar to the traveling salesman problem that I am trying to make recursive. I think it is working but I am having some trouble getting the appending to work correctly on large datasets. Here is what I have...main should be written to be recursive so I can call a variable number of recursions...https://play.golang.org/p/Lz8arHybFr
package main
type Foo struct {
StartPoint string
EndPoint string
distance int
}
func (f *Foo) Connects(endFoo *Foo) bool {
return f.EndPoint == endFoo.StartPoint
}
func (f *Foo) Completes(endFoo *Foo) bool {
return f.StartPoint == endFoo.EndPoint
}
var fl = []*Foo{
// many foo in here
}
func main() {
completeList := [][]*Foo{}
for _, first := range fl {
for _, second := range fl {
if second.Connects(first) {
if second.Completes(first) {
l := []*Foo{
first, second,
}
completeList = append(completeList, l)
}
//if the connection is made, but not complete, keep going
for _, third := range fl {
if third.Connects(second) {
if first.Completes(third) {
l := []*Foo{
first, second, third,
}
completeList = append(completeList, l)
}
}
}
}
}
}
}