Last active
January 3, 2017 19:50
-
-
Save robvadai/f8c9e67028bdde76400ace58aa25fb39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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