0

I have problem while reversing and checking palindrome for a number of specific base (other than 10). For example:- let's take 87. The Palindrome number is found as follows:

87+78= 165+ 561 = 726 + 627= 1353 + 3531 = Palindrome !

This method works fine for a number with base 10. But how to do this for another number with different base. Just like, 1211 with base 3 forms Palindrome 112211 and 3112 with base 4 forms Palindrome 233332 . I used these results to test my code. But the output doesn't match. Please guide me and share your precious knowledge, I shall be glad and thankful to you :)


  • How could we possibly find your error without seeing your code? You have a bug, which is not what we are here for. There is codereview.se, but I think they are more about style than bugs. – Ross Millikan Apr 30 '17 at 04:37
  • I'm not sure what you're asking here. The same tactics will work on a different base. If your problem is with the addition in each base, then that's a different issue. Furthermore, considering you are coding, it could be an error in conversion. – John Lou Apr 30 '17 at 04:37
  • Please forgive me if I couldn't explain my point ! I just don't know exactly where the mistake is :( – HN Learner Apr 30 '17 at 04:39
  • Sure, but what are you asking for? How to do the arithmetic, or whether the code is wrong? – John Lou Apr 30 '17 at 04:42
  • Sir I just wanted to ask that how to do it mathematically. I am not concerned with the code here :) – HN Learner Apr 30 '17 at 04:44

1 Answers1

1

Mathematically, arithmetic in different bases is not too complicated. The only thing you have to change is your definition of "carrying" for example, $54_9 + 76_9 = \underline{12_9}$ $\underline{10_9}$ which is then equal to $141_9$. Notice how instead of carrying numbers once they reached $10$, we carry after they reach $9$.

Here's an example. Let's take $56_7$.

$56_7 + 65_7 = \underline{11_7}$ $\underline{11_7} = 154_7$

$154_7 + 451_7 = \underline{5_7}$ $\underline{10_7}$ $\underline{5_7} = 635_7$

$635_7 + 536_7 = \underline{11_7}$ $\underline{6_7}$ $\underline{11_7} = 1504_7$

$1504_7 + 4051_7 = \underline{5_7}$ $\underline{5_7}$ $\underline{5_7}$ $\underline{5_7} = 5555_7$

And there's your palindrome number!

John Lou
  • 2,388
  • 13
  • 16