Skip to content

Instantly share code, notes, and snippets.

@ClassCubeGists
Last active May 18, 2018 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClassCubeGists/bfb45c718816ecaad9234f3302e4c8d2 to your computer and use it in GitHub Desktop.
Save ClassCubeGists/bfb45c718816ecaad9234f3302e4c8d2 to your computer and use it in GitHub Desktop.
FrogSimulation solution - AP 2018 FRQ - https://clsc.be/28
public boolean simulate() {
int hops = 0;
int cntPos = 0;
while (hops < maxHops && cntPos >= 0 && cntPos < goalDistance) {
cntPos += hopDistance();
hops++;
}
return cntPos >= goalDistance;
}
public double runSimulation(int num) {
int good = 0;
for (int i=0; i<num; i++)
if (simulate())
good++;
return (double)good / num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment