https://github.com/ioleo/code-kata-acyclic-graph-distance
Acyclic graph distance code kata in Scala.
https://github.com/ioleo/code-kata-acyclic-graph-distance
code-kata
Last synced: 5 months ago
JSON representation
Acyclic graph distance code kata in Scala.
- Host: GitHub
- URL: https://github.com/ioleo/code-kata-acyclic-graph-distance
- Owner: ioleo
- Created: 2017-01-30T23:39:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-02T23:27:20.000Z (about 9 years ago)
- Last Synced: 2025-06-11T00:05:34.868Z (8 months ago)
- Topics: code-kata
- Language: Scala
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# code-kata-acyclic-graph-distance
You are given an array representing M cities connected with M-1 roads.
Compute the amount of cities reachable in 1 to M-1 steps from specified start point (the capital city).
```
val input: Array[Int] = Array(9, 1, 4, 9, 0, 4, 8, 9, 0, 1)
```
Which represents following information:
* City #0 has direct road to city #9
* City #1 has direct road with itself (special case -> this is the capital city)
* City #2 has direct road to city #4
* City #3 has direct road to city #9
* ...
* City #8 has direct road to city #0
* City #9 has direct road to city #1
> Note: the "from" city number is the index of an element, the "to" city number is the value of an element.
```
val expectedOutput: Array[Int] = Array(1, 3, 2, 3, 0, 0, 0, 0, 0)
```
Which represents following information:
* There are 1 cities at reachable in 1 steps
* There are 3 cities at reachable in 2 steps
* There are 2 cities at reachable in 3 steps
* There are 3 cities at reachable in 4 steps
* ...
* There are 0 cities at reachable in 8 steps
* There are 0 cities at reachable in 9 steps
> Note: the "number of steps" is the index of an element plus one, the "number of cities" at given distance is the value of an element.