Tripartite Palindromic Partition of Integer (HP 50g) Challenge
|
02-17-2023, 03:57 PM
(This post was last modified: 02-17-2023 11:21 PM by Albert Chan.)
Post: #12
|
|||
|
|||
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Greedy search algorithm work with other base too.
We redo OP example, but this time assumed n is really hex digits. Maximize x, assume no carry. Code: 808182838485868788 Maximize x: y=0 → z=6 → c=1 → x=5 Code: 808182838485868788 Continue fill the digits, we ended-up with a bad x, with digit ? = -1 We backtrack for valid x, 8? --> 7F, and continue Code: 808182838485868788 808182838485868788 y=0 → z=8 → c=1 → x=9. With y center = 2, we have the triplets. Code: 808182838485868788 0x808182838485868788 = 0x715B557F99F755B517 + 0xF000000020000000F + 0x262D03E88E30D262 To simplify backtracking, we could assume y digits start with 1. Now, x is not maximized, but it is not OP requirement, thus OK. Backtracking is simply changing y=1 to y=0. All generated x digits are good. Bonus: we have an intuitive proof that n = sum of palindrome triplets. (when x digits all filled) 0x808182838485868788 = 0x714B4570880754B417 + 0xF111110161011111F + 0x252C02E66E20C252 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)