#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main ( int argc, char *argv[] )
{
int number_of_steps = 30;
int repetition = 6500000;
int distance = 0;
int total_distance = 0;
double expected_distance;
int i, j;
for ( i = 0; i < repetition; i++ ) {
for ( j = 0; j < number_of_steps; j++) {
distance
+= rand() & 1 ? -1 : 1; }
total_distance += distance * distance;
distance = 0;
}
expected_distance
= sqrt((float) total_distance
/ repetition
);
printf ( "%g\n", expected_distance
); return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
I2luY2x1ZGUgICAgPHRpbWUuaD4KI2luY2x1ZGUgICAgPHN0ZGxpYi5oPgojaW5jbHVkZSAgICA8c3RkaW8uaD4KI2luY2x1ZGUgICAgPG1hdGguaD4KCmludCBtYWluICggaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSApCnsKCiAgaW50IG51bWJlcl9vZl9zdGVwcyA9IDMwOwogIGludCByZXBldGl0aW9uID0gNjUwMDAwMDsKICBpbnQgZGlzdGFuY2UgPSAwOwogIGludCB0b3RhbF9kaXN0YW5jZSA9IDA7CiAgZG91YmxlIGV4cGVjdGVkX2Rpc3RhbmNlOwogIGludCBpLCBqOwoKICBzcmFuZCh0aW1lKE5VTEwpKTsKCiAgZm9yICggaSA9IDA7IGkgPCByZXBldGl0aW9uOyBpKysgKSB7CgogICAgZm9yICggaiA9IDA7IGogPCBudW1iZXJfb2Zfc3RlcHM7IGorKykgewogICAgICBkaXN0YW5jZSArPSByYW5kKCkgJiAxID8gLTEgOiAxOwogICAgfQoKICAgIHRvdGFsX2Rpc3RhbmNlICs9IGRpc3RhbmNlICogZGlzdGFuY2U7CiAgICBkaXN0YW5jZSA9IDA7CgogIH0KCiAgZXhwZWN0ZWRfZGlzdGFuY2UgPSBzcXJ0KChmbG9hdCkgdG90YWxfZGlzdGFuY2UgLyByZXBldGl0aW9uKTsKCiAgcHJpbnRmICggIiVnXG4iLCBleHBlY3RlZF9kaXN0YW5jZSApOwogIHJldHVybiBFWElUX1NVQ0NFU1M7Cn0gICAgICAgLyogLS0tLS0tLS0tLSAgZW5kIG9mIGZ1bmN0aW9uIG1haW4gIC0tLS0tLS0tLS0gKi8=