Skip to content

Instantly share code, notes, and snippets.

@robvadai
Last active January 3, 2017 19:50
Show Gist options
  • Save robvadai/f8c9e67028bdde76400ace58aa25fb39 to your computer and use it in GitHub Desktop.
Save robvadai/f8c9e67028bdde76400ace58aa25fb39 to your computer and use it in GitHub Desktop.
import scala.annotation.tailrec
def findNumberOfSteps(start: Int, target: Int, distance: Int): Int = {
@tailrec
def progressUntilTargetReached(numberOfSteps: Int, currentPosition: Int): Int = {
if (currentPosition >= target) {
numberOfSteps
} else {
progressUntilTargetReached(numberOfSteps + 1, currentPosition + distance)
}
}
progressUntilTargetReached(0, start)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment