Post Reply 
HP 50g: Programming Problem: Integer Partition in Palindromic Integers
02-13-2018, 09:31 PM
Post: #21
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
Meanwhile here's a shorter version of the programme:

Size: 261.5 Bytes

CkSum: # E377h

Code:
« 0 SWAP
  DO SWAP 1 + SWAP DUPDUP →STR DUP SREV DUP2 SAME
    IF
    THEN DROP2
    ELSE OBJ→ 1 SAME
      IF
      THEN DROP2 1 - SWAP 1 + 1 1
      ELSE 1. OVER SIZE 2. / DUP IP 5. ROLLD SUB DUPDUP 1. 6. PICK SUB SREV + OBJ→ ROT OVER <
        IF
        THEN DROP OBJ→ 1 - →STR DUP 1. 4. PICK SUB SREV + OBJ→ DUP
        END UNROT DROP2
      END
    END DUP 4 ROLLD - DUP NOT
  UNTIL
  END DROP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
Find all posts by this user
Quote this message in a reply
02-18-2018, 01:50 AM
Post: #22
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
Hello Gerald H, in my previous program I wanted to see if I can have an IFTE structure inside another one and it did work. The problem with comparing the two strings got me thinking that it is not necessary to compare the hole number but just last half of it. Now the program is 195 bytes and the check-sum is # 4007h. Thanks for the remarks that help improve the program.
Code:
«
 WHILE DUP →STR DUPDUP SIZE DUP 1 >
 REPEAT
  2 / SWAP 1 PICK3 SUB DUP OBJ→ 1 - →STR
  IF DUP2 SIZE SWAP SIZE ==
  THEN
   4 ROLL 4 PICK 1 + OVER SIZE SUB OBJ→
   PICK3 1 6 PICK FLOOR SUB OBJ→ > UNROT IFTE
   DUP 1 4 ROLL FLOOR SUB + OBJ→ SWAP OVER -
  ELSE
   4 DROPN 1 - 1
  END
 END 3 DROPN
»
Find all posts by this user
Quote this message in a reply
02-18-2018, 06:19 AM (This post was last modified: 02-18-2018 07:54 AM by Gerald H.)
Post: #23
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
I have found two numbers that cause problems for the programme.

5186197216518619721

causes the programme to go into an infinite loop &

5936136460563669585

returns

5936136459593613645
970049700
6161
77
2

three of which are not palindromes.
Find all posts by this user
Quote this message in a reply
02-19-2018, 04:39 PM (This post was last modified: 02-19-2018 04:42 PM by Gerald H.)
Post: #24
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
Here is my version of Juan14's programme, now gives correct answers for any positive integer:

SIZE: 279.

CKSM: # 55A3h

Code:
« 0. SWAP
  WHILE SWAP 1. + SWAP DUP 9 >
  REPEAT DUP →STR DUP SREV OBJ→ 1 SAME
    IF
    THEN DROP 1 - SWAP 1
    ELSE DUP SIZE 2. / SWAP 1. PICK3 SUB DUPDUP 1. 5. PICK FLOOR SUB SREV + 4 PICK OVER OBJ→ <
      IF
      THEN DROP OBJ→ 1 - →STR DUP 1. 4. ROLL IP SUB SREV +
      ELSE UNROT DROP2
      END OBJ→ SWAP OVER - ROT SWAP
    END
  END DUP NOT
  IF
  THEN DROP 1. -
  ELSE SWAP
  END DUPDUP 2. + ROLLD →LIST SWAP R→I →TAG
»
Find all posts by this user
Quote this message in a reply
02-25-2018, 03:41 PM
Post: #25
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
Good news!

Here is a proof that any integer can be partitioned in THREE palindromes:

https://arxiv.org/pdf/1602.06208v1.pdf

So the challenge is to produce a programme that returns such tripartite partitions.
Find all posts by this user
Quote this message in a reply
Post Reply 




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