Group Group Group Group Group Group Group Group Group

Chapter 37: Graph Challenges

In challenge 1 solution, we are passing references to “paths” function and then finding out the number of paths from one vertex to another, which seems to be quite confusing in first look.
But as per my solution(plz pardon me, if I am wrong), we can achieve the same efficiency in very less code.
Below is my solution -

public func numberOfPaths(from source: Vertex<Element>, to destination: Vertex<Element>) -> Int {
    var paths = 0
    let edgesForSource = edges(from: source)
    edgesForSource.forEach {
        if $0.destination == destination {
            paths += 1
        } else {
            paths += numberOfPaths(from: $0.destination, to: destination)
        }
    }
    return paths
  }

@kelvin_lau can you plz confirm on this