# Chapter 37: Graph Challenges

**URL:** <https://forums.kodeco.com/t/chapter-37-graph-challenges/113683>\
**Category:** Data Structures & Algorithms in Swift\
**Created:** [July 1, 2020, 10:40am UTC](https://forums.kodeco.com/t/chapter-37-graph-challenges/113683 "2020-07-01T10:40:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulkitap](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pulkitap/32/81494_2.png) [@pulkitap](https://forums.kodeco.com/u/pulkitap)\
**Post date:** [July 1, 2020, 10:40am UTC](https://forums.kodeco.com/t/chapter-37-graph-challenges/113683/1 "2020-07-01T10:40:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [March 19, 2021, 12:39pm UTC](https://forums.kodeco.com/t/chapter-37-graph-challenges/113683/2 "2021-03-19T12:39:14Z")

</div>

@jomoka Can you please help with this when you get a chance? Thank you - much appreciated! :]
