Esempio n. 1
0
void findNext() {
    unsigned int t = nextTriangle(), p = nextPent(), h = nextHex();
    do {
        while (p < t)
        {
            p = nextPent();
            printf("%d %d %d\n", t, p, h);
        }
        while (h < t)
        {
            h = nextHex();
            printf("%d %d %d\n", t, p, h);
        }
        while (t < p)
        {
            t = nextTriangle();
            printf("%d %d %d\n", t, p, h);
        }
        while (p < h)
        {
            p = nextPent();
            printf("%d %d %d\n", t, p, h);
        }
    } while ((t != p) || (p != h));
    printf("%d %d %d / %d %d %d\n", t, p, h, currentTermTriangle, currentTermPent, currentTermHex);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    mpz_t counter;
    mpz_t triangleValue;
    unsigned int factors;
    unsigned int previousFactors = 0;
    mpz_init_set_ui(counter, 1);
    mpz_init(triangleValue);
    mpz_init_set_ui(previousTriangleCounter, 0);
    
    while (1) 
    {
        nextTriangle(triangleValue);
        factors = factorCount(triangleValue);
        if (previousFactors < factors)
        {
            previousFactors = factors;
            printf("Number %s has triangle %s and %d factors\n", mpz_get_str(NULL, 10, counter), mpz_get_str(NULL, 10, triangleValue), factors);
        }
        if (factors >= STOP_COUNT)
            break;
        mpz_add_ui(counter, counter, 1);
    }
    return 0;
}
Esempio n. 3
0
void seekFirst() {
    while (nextTriangle() != 40755)
        ;
    printf("At triangle term %d\n", currentTermTriangle);
    while (nextPent() != 40755)
        ;
    printf("At pent term %d\n", currentTermPent);
    while (nextHex() != 40755)
        ;
    printf("At hex term %d\n", currentTermHex);
}
 vector<vector<int> > generate(int numRows) {
     if(0 == numRows){
         vector<vector<int> > result;
         return result;
     }
     vector<vector<int> > result(numRows);
     vector<int> first(1,1);
     result[0] = first;
     for(int i=1;i<numRows;i++){
         result[i] = nextTriangle(result[i-1]);
     }
     return result;
 }
Esempio n. 5
0
void test()
{
    resetTriangle();
    printf("Triangle: 1 ");
    for (int i = 1; i <= 10; i++)
        printf("%d ", nextTriangle());
    printf("\n");
    resetPent();
    printf("Pentagonal: 1 ");
    for (int i = 1; i <= 10; i++)
        printf("%d ", nextPent());
    printf("\n");
    resetHex();
    printf("Hexagonal: 1 ");
    for (int i = 1; i <= 10; i++)
        printf("%d ", nextHex());
    printf("\n");
    resetTriangle();
    resetPent();
    resetHex();
}