Example #1
0
if (realpath($argv[0]) == realpath(__FILE__)) {
    printf("sum(10) = %d\n", Example::sum(10));
    printf("horner([2,4,6], 2, 57) = %d\n", Example::horner(array(2, 4, 6), 2, 57));
    printf("horner2([2,4,6], 2, 57) = %d\n", Example::horner2(array(2, 4, 6), 2, 57));
    printf("factorial(10) = %d\n", Example::factorial(10));
    printf("findMaximum([3,1,4,1,5,9,2], 7) = %d\n", Example::findMaximum(array(3, 1, 4, 1, 5, 9, 2), 7));
    printf("gamma = %f\n", Example::gamma());
    printf("geometricSeriesSum1(10, 6) = %d\n", Example::geometricSeriesSum(10, 6));
    printf("geometricSeriesSum2(10, 6) = %d\n", Example::geometricSeriesSum2(10, 6));
    printf("geometricSeriesSum3(10, 6) = %d\n", Example::geometricSeriesSum3(10, 6));
    $arg = array(2, 4, 6, 8);
    Example::prefixSums($arg, 4);
    printf("prefixSums([2,4,6,8], 4) = %s\n", join(',', $arg));
    printf("fibonacci1(5) = %d\n", Example::fibonacci(10));
    printf("fibonacci2(5) = %d\n", Example::fibonacci2(10));
    printf("fibonacci3(5) = %d\n", Example::fibonacci3(10));
    printf("fibonacci4(5, 2) = %d\n", Example::fibonacci4(10, 2));
    $arg = array(3, 1, 4, 1, 5, 9, 2);
    $buckets = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    Example::bucketSort($arg, 7, $buckets, 10);
    printf("bucketSort({3,1,4,1,5,9,2}, 10) = %s\n", join(',', $arg));
    $arg = array(3, 1, 4, 1, 5, 9, 2);
    Example::mergeSort($arg, 0, 7);
    printf("mergeSort({3,1,4,1,5,9,2}, 10) = %s\n", join(',', $arg));
    printf("binarySearch({1,1,2,3,4,5,9}, 5, 0, 7) = %s\n", Example::binarySearch(array(1, 1, 2, 3, 4, 5, 9), 5, 0, 7));
    printf("binom(5, 2) = %d\n", Example::binom(5, 2));
    printf("computePi(10000) = %f\n", Example::computePi(10000));
    one();
    one2();
    g();
}