diff options
-rw-r--r-- | src/main.c | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -43,14 +43,36 @@ void find_largest_palindromes(char* data) { // 0 1 2 3 4 5 6 // r a c e c a r + // 0 1 2 3 4 5 + // a b c c b a + while(data[cursor] != '\0') { + // Need to align with the center + // Advance end one to see if this is an even numbered palindrome + if(data[end + 1] != '\0') { + ++end; + } + // If it's not an even numbered, let's see if it's odd numbered + if(start > 0 && data[start] != data[end]) { + --start; + } + // Looks like it's not either, reset and continue + if(data[start] != data[end]) { + ++cursor; + start = cursor; + end = cursor; + continue; + } + + // It seems we have found a palindrome, let's see how big... while(data[start] == data[end]) { - if(start > 0) { - --start; - } if(data[end + 1] != '\0') { ++end; } + if(start > 0) { + --start; + } + } if(end - start - 1 > largest) { largest = end - start - 1; |