Skip to content

Instantly share code, notes, and snippets.

@mpadmore
Created February 28, 2018 21:11
Show Gist options
  • Save mpadmore/6cd916062fc3f65ef69ec958821fbf29 to your computer and use it in GitHub Desktop.
Save mpadmore/6cd916062fc3f65ef69ec958821fbf29 to your computer and use it in GitHub Desktop.
How many frog hops from x to y
<cfscript>
// A small frog wants to get to the other side of the road.
// The frog is currently located at position X and wants to get to a position greater than or equal to Y.
// The small frog always jumps a fixed distance, D.
// Count the minimal number of jumps that the small frog must perform to reach its target.
// Write a function that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.
// For example, given:
// X = 10
// Y = 85
// D = 30 the function should return 3
numeric function solution(
required numeric X,
required numeric Y,
required numeric D)
{
// Write function code here
// then press "run code" to
// check it
answer = ceiling((arguments.y - arguments.x) / arguments.d);
return answer;
}
writeOutput(solution(10,85,30));
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment