Post Reply 
HP 50g: Programming Problem: Integer Partition in Palindromic Integers
02-01-2018, 11:20 AM (This post was last modified: 02-07-2018 05:38 PM by Gerald H.)
Post: #2
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
Edited to "39g programme" from "38G programme" - sorry for the error.

Well, not much progress made on this, unless members are keeping their solutions secret.

Meanwhile I have produced a complete solution for the 39g, although I do not claim that the partitions share the characteristic of having a minimum number of elements in the respective palindromic partition.

The 39g programme has one sub programme, N2DS, which for natural number input Ans produces a list of digits in list L2, eg for input

23405

L2 will contain

{5,0,4,3,2}

which may in itself be useful.

Code:
N2DS

Ans►T:
CLRVAR L2:
FOR I=1 TO INT(LOG(T)+1) STEP 1;
 T MOD 10:
CONCAT(L2,{Ans})►L2:
INT(T/10)►T:
END:

The main programme, P24U, which for natural number input Ans produces a list of the palindromic partition members in descending order in list L1. eg For input

987654321678

L1 will contain

Code:
{899999999998,79999999997,6999999996,599999995,49999994,3999993,299992,19991,999​,595,66,9,8,8,7,6,5,5,4,4,3,2,1}

Code:
P24U

Ans►N:
IF Ans<10
THEN
{N}►L1:
ELSE
N:
RUN N2DS:
{L2(1)}►L1:
SUB L2;L2;2;12:
FOR I=1 TO SIZE(L2) STEP 1;
 L2(I):
Ans►H:
IF H
THEN 
IF H>1
THEN
11-H:
END:
CONCAT(L1,{Ans,10^I*H-Ans})►L1:
END:
END:
END:
REVERSE(SORT(L1))►L1:

As the 39g is limited to 12 digit integers, the above programme solves the problem completely on that machine.

However, as the algorithm produces two elements of the partition for each digit, the method becomes impractical on the 49G for , say, 6,000 digit numbers.

I again encourage members to apply themselves to this interesting, if unimportant, problem.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers - Gerald H - 02-01-2018 11:20 AM



User(s) browsing this thread: 1 Guest(s)