Post Reply 
HP 50g: Programming Problem: Integer Partition in Palindromic Integers
02-07-2018, 05:31 PM
Post: #10
RE: HP 50g: Programming Problem: Integer Partition in Palindromic Integers
Meanwhile here's my 50g programme which gives correct but perhaps not minimal answers to the problem.

The size of the returned partitions is again log2(SIZE(N)), as for Juan14's programme, but integers up to 40,000 digits have been processed correctly.

Size: 557.5 Bytes

CkSum: # 6711h

Code:
« 0 SWAP
  WHILE SWAP 1 + SWAP DUPDUP →STR DUPDUP SREV SAME
    IF
    THEN DROP 0.
    ELSE DUP SIZE 2. IDIV2 DUP 4 ROLLD + 1 SWAP SUB DUP OBJ→ 10 ROT SIZE 1. - R→I ^ OVER SAME
      IF
      THEN SWAP
        IF
        THEN 0.
        ELSE 10 * 1.
        END SWAP
      END 1 - →STR DUP SREV ROT
      IF
      THEN TAIL
      END + DUP OBJ SWAP DUP SIZE 2. IDIV2 DUP UNROT
      IF
      THEN 1. + SUB DUP TAIL SWAP HEAD OBJ→ 1 + SWAP +
      ELSE SUB 1 SWAP +
      END OBJ→ 1 + DUP 2. <
      IF
      THEN 0
      ELSE →STR DUP HEAD "1" SAME OVER 2. 2. SUB "0" SAME NOT AND
        IF
        THEN TAIL DUP SREV
        ELSE DUP TAIL SWAP HEAD OBJ→ 1 - DUP NOT
          IF
          THEN DROP TAIL 9
          END SWAP + DUP SREV TAIL
        END + OBJ→
      END ROT OVER >
      IF
      THEN NIP
      ELSE DROP
      END DUP2 SAME NOT
    END
  REPEAT DUP 4. ROLLD -
  END DROP SWAP DUPDUP 2. + ROLLD →LIST SWAP →TAG
»
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-07-2018 05:31 PM



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