Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solution for the Frog Simulation free response on the 2018 AP computer science exam - https://compsci.rocks
public double runSimulation(int num) {
int good = 0;
for (int i=0; i<num; i++)
if (simulate())
good++;
return (double)good / num;
}
public boolean simulate() {
int hops = 0;
int cntPos = 0;
while (hops < maxHops && cntPos >= 0 && cntPos < goalDistance) {
cntPos += hopDistance();
hops++;
}
return cntPos >= goalDistance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.