Last active
May 18, 2018 12:53
-
-
Save ClassCubeGists/bfb45c718816ecaad9234f3302e4c8d2 to your computer and use it in GitHub Desktop.
FrogSimulation solution - AP 2018 FRQ - https://clsc.be/28
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
public boolean simulate() { | |
int hops = 0; | |
int cntPos = 0; | |
while (hops < maxHops && cntPos >= 0 && cntPos < goalDistance) { | |
cntPos += hopDistance(); | |
hops++; | |
} | |
return cntPos >= goalDistance; | |
} |
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
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