Skip to content

Commit

Permalink
made tailrec
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxet1000 committed Jul 14, 2024
1 parent 5ba6595 commit fc24b58
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ class ScoreList {
* and repeats this process for the expanded part until no skips are found in an expanded part.
*/
@Synchronized
fun getNumberOfSkipsByInterval(
tailrec fun getNumberOfSkipsByInterval(
values: IntArray,
firstIndexCurrentInterval: Int,
lastIndexCurrentInterval: Int
lastIndexCurrentInterval: Int,
numberOfSkipsIntermediate: Int = 0
): Int {
if (lastIndexCurrentInterval < firstIndexCurrentInterval) return 0
if (lastIndexCurrentInterval < firstIndexCurrentInterval) return numberOfSkipsIntermediate
var nbOfSkips = 0
var nextLastIndex = lastIndexCurrentInterval
for (i in firstIndexCurrentInterval..lastIndexCurrentInterval) {
Expand All @@ -83,7 +84,7 @@ class ScoreList {
if (lastIndexCurrentInterval + nbOfSkips < values.size) nextLastIndex++
}
}
return nbOfSkips + getNumberOfSkipsByInterval(values, lastIndexCurrentInterval + 1, nextLastIndex)
return getNumberOfSkipsByInterval(values, lastIndexCurrentInterval + 1, nextLastIndex, nbOfSkips)
}

/**
Expand Down

0 comments on commit fc24b58

Please sign in to comment.