Finding the next Palindrome



Hello, here's a quick post I'm making for a simple program. There will likely be another as my professor is currently making me do more basic programs at this point instead of a more major project like the calculator.

This programs does one task: when given a number, it will find the next palindrome after the number. You can find it here on github.

It does some other tasks as well such as validating if the input was a number and making sure the number can be turned into an integer.

The finding of the next palindrome is done by checking the first half of the number and comparing its reverse to the latter half of the number.

If the reversed first half is larger than the latter half, the output will just be the first half combined with the latter half being the reversed first half. In odd length numbers, the middle number is increased by 1.

 If the reversed first half is smaller than or equal to the latter half, the output will be the first half plus 1 and the reverse of the new first half. In odd length numbers, the middle number is increased by 1 as well.

There is also support for negative numbers. However, instead of the next being the larger palindrome, it's the smaller palindrome. If the number -12343 was inputted, the output would be  -12421 instead of -12321. Making it go the other way would require more lines of code and would likely make this way more complex, so I just decided to get the smaller palindrome instead of the larger palindrome.

The program does not support decimal numbers. However if a number is inputted with only 0s in decimal places, such as 35.000, the program will accept it.

That's it. Just a short post for a short program. There will likely be another small program released soon, though not likely at the end of the week. Until then, see you next time.

Comments

Popular posts from this blog

Version 2:The Not-So Barebones Clicker

A Prime Factorization Algorithm that Uses a Text File

Aesthetico Ultimate Designer - A Python Turtle Program