Example #1
0
int solve(int p) {
    int len = 2*p;
    int hi = pow(10, p);
    int lo = pow(10, p-1);
    int digits[len];
    int i;
    for (i = 0; i < hi; i++) {
        int j;
        int num = i;
        for (j = p - 1; j >= 0; j--) {
            digits[j] = 9 - (num % 10);
            num /= 10;
        }

        for (j = 0; j < p; j++) { // Fill second half
            digits[len-1-j] = digits[j];
        }

        int palindrome = from_digits(digits, len);

        for (j = hi - 1; j >= lo; j--) {
            int q = palindrome / j;
            int m = palindrome % j;
            if (m == 0 && q < hi && q > lo) {
                return palindrome;
            }
        }
    }
    return -1;
}
Example #2
0
TEST(digit, from_digits) {
    int digits1[] = {4,5,6,6};
    EXPECT_EQ(4566, from_digits(digits1, 4));
    int digits2[] = {2};
    EXPECT_EQ(2, from_digits(digits2, 1));
}
Example #3
0
int counter::rotate()
{
    m_ds.push_back(m_ds.front());
    m_ds.pop_front();
    return from_digits();
}