Exemple #1
0
int main()
{
    std::vector<number> P;
    P.push_back(1);
    P.push_back(1);
    number curr = 1;
    while (curr)
    {
        number accum = 0;
        number k = 1;
        while (1)
        {
            number g = get_g(k);
            if (g > P.size())
            {
                break;
            }
            accum += ((k % 2 == 0)?-1:1) * P[P.size() - g];
            k = next_k(k);
        }
        curr = accum % bound;
        P.push_back(curr);
    }
    std::cout << P.size() - 1<< std::endl;
}
    MySaw2() {
        // 1. set the calculation function.
        if (isAudioRateIn(0)) {
            // if the frequency argument is audio rate
            set_calc_function<MySaw2,&MySaw2::next_a>();
        } else {    
        // if thene frequency argument is control rate (or a scalar).
            set_calc_function<MySaw2,&MySaw2::next_k>();
        }   

        // 2. initialize the unit generator state variables.
        // initialize a constant for multiplying the frequency
        mFreqMul = 2.0 * sampleDur();
        // get initial phase of oscillator
        mPhase = in0(1);

        // 3. calculate one sample of output.
        if (isAudioRateIn(0)) {
            next_a(1);
        } else {
            next_k(1);
        }
     
    }
    void do_search(std::size_t k, ResultCallback callback, SearchHeuristic heuristic) {
        if (toroid_m.right_of(&toroid_m.header_m) == &toroid_m.header_m) {
            ++solutions_m;

#if ADOBE_DLX_VERBOSE
            std::cout << adobe::indents(tab_count_m) << "<solved/>" << std::endl;
#endif

            for (std::size_t i(0); i < k; ++i)
                callback(toroid_m.row_index_of(output_m[i]), i + 1 == k);

            return;
        }

        std::size_t next_k(k + 1);

        toroid_header_t* c(heuristic(toroid_m));

#if ADOBE_DLX_VERBOSE
        ++tab_count_m;
        std::cout << adobe::indents(tab_count_m) << "<c"
                  << toroid_m.column_index_of(toroid_m.down_of(c)) << ">" << std::endl;
#endif

        toroid_m.cover_column(c);

        // branch on each node in this column
        for (toroid_node_t* r(toroid_m.down_of(c)); r != c; r = toroid_m.down_of(r)) {
#if ADOBE_DLX_VERBOSE
            std::cout << adobe::indents(tab_count_m) << "<r" << toroid_m.row_index_of(r) << ">"
                      << std::endl;
#endif

            output_m[k] = r;

            // cover or purify each node on the same row as the node we're branching on
            for (toroid_node_t* j(toroid_m.right_of(r)); j != r; j = toroid_m.right_of(j)) {
                if (j->color_m == 0) {
#if ADOBE_DLX_VERBOSE
                    std::cout << adobe::indents(tab_count_m) << "<c" << toroid_m.column_index_of(j)
                              << ">" << std::endl;
#endif
                    toroid_m.cover_column(toroid_m.column_of(j));
                } else if (j->color_m > 0) {
#if ADOBE_DLX_VERBOSE
                    std::cout << adobe::indents(tab_count_m) << "<p" << toroid_m.column_index_of(j)
                              << ">" << std::endl;
#endif
                    toroid_m.purify(j);
                }
            }

#if ADOBE_DLX_VERBOSE
// std::cout << *this << std::endl;
#endif

            do_search(next_k, callback, heuristic);

            if (solutions_m >= max_solutions_m)
                return;

            r = output_m[k];

            c = toroid_m.column_of(r);

            // undo the cover/purify
            for (toroid_node_t* j(toroid_m.left_of(r)); j != r; j = toroid_m.left_of(j)) {
                if (j->color_m == 0) {
#if ADOBE_DLX_VERBOSE
                    std::cout << adobe::indents(tab_count_m) << "</c" << toroid_m.column_index_of(j)
                              << ">" << std::endl;
#endif
                    toroid_m.uncover_column(toroid_m.column_of(j));
                } else if (j->color_m > 0) {
#if ADOBE_DLX_VERBOSE
                    std::cout << adobe::indents(tab_count_m) << "</p" << toroid_m.column_index_of(j)
                              << ">" << std::endl;
#endif
                    toroid_m.unpurify(j);
                }
            }

#if ADOBE_DLX_VERBOSE
            std::cout << adobe::indents(tab_count_m) << "</r" << toroid_m.row_index_of(r) << ">"
                      << std::endl;
#endif
        }

        toroid_m.uncover_column(c);

#if ADOBE_DLX_VERBOSE
        std::cout << adobe::indents(tab_count_m) << "</c"
                  << toroid_m.column_index_of(toroid_m.down_of(c)) << ">" << std::endl;
        --tab_count_m;
#endif
    };