Skip to content

Instantly share code, notes, and snippets.

@gilrosenthal
Created October 9, 2015 17:07
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 gilrosenthal/53e9db1fa4a3f00f6610 to your computer and use it in GitHub Desktop.
Save gilrosenthal/53e9db1fa4a3f00f6610 to your computer and use it in GitHub Desktop.
int ability = 256;
int numberOfAtBats = 25;
int hitLED = 2;
int missLED = 13;
int totalUnderTwo = 0;
int ledPin[] = {7,8,9,10,11,12};
void setup() {
for (int i =0;i<6;i++)
{
pinMode(ledPin[i], OUTPUT);
}
randomSeed(analogRead(A0));
pinMode(hitLED, OUTPUT);
pinMode(missLED, OUTPUT);
Serial.begin(9600);
for(int g = 0; g <25; g++){
int TwoOrLess = 0;
for (int t = 0; t < 100; t++) {
int hitCount = 0;
for (int x = 0; x < numberOfAtBats; x++) {
int f = random(1000);
if (f <= ability) {
hitCount++;
}
}
if (hitCount <= 2) {
digitalWrite(hitLED, HIGH);
TwoOrLess++;
delay(10);
}
else {
digitalWrite(missLED, HIGH);
delay(10);
};
digitalWrite(missLED, LOW);
digitalWrite(hitLED, LOW);
}
Serial.print("Number of sets when he hit 2 or less hits: ");
Serial.println(TwoOrLess);
totalUnderTwo+=TwoOrLess;
}
Serial.print("Under 2: ");
Serial.println(totalUnderTwo);
Serial.print("P-Value: ");
float result = ((float)(totalUnderTwo)/(float)2500)*1000;
Serial.println(result);
displayBinary(result);
}
void loop() {}
void displayBinary(byte numToShow)
{
for (int i =0;i<6;i++)
{
if (bitRead(numToShow, i)==1)
{
digitalWrite(ledPin[i], HIGH);
}
else
{
digitalWrite(ledPin[i], LOW);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment