Post Reply 
Tripartite Palindromic Partition of Integer (HP 50g) Challenge
03-04-2023, 03:57 AM (This post was last modified: 03-05-2023 11:20 AM by Gerald H.)
Post: #41
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Edit: The programme as below causes errors, some, believe it or not, introduced by me.
Please do not use - remains here for documentary considerations.


I have shortened ALGO4

CKSUM 3914h
SiIZE 9277.5

Code:
« → d p1 p2 p3
   « p1 SIZE ZEROLST
p1 SIZE 2 / IP p1
SIZE p2 SIZE p3
SIZE p1 1 GET p2 1
GET p3 1 GET 0 0 0
 c m l1 l2 l3 x y
z d1 d2 ci
  → « x y + z + 10
/ IP 'ci' STO c 1
ci PUT 'c' STO d 2
m * 3 - GET 'd1'
STO d 2 m * 2 - GET
'd2' STO
      IF z d1 <
      THEN d2 y -
10 MOD 'x' STO
      ELSE d2 y - 1
- 10 MOD 'x' STO
      END p1 3 x
PUT l1 2 - x PUT
'p1' STO d1 z - 1 -
10 MOD 'y' STO p2 2
y PUT l2 1 - y PUT
'p2' STO d 2 GET p1
2 GET - y - ci - 10
MOD 'z' STO p3 2 z
PUT l3 1 - z PUT
'p3' STO p1 2 GET y
+ z + ci + d 2 GET
- 10 / IP 'ci' STO
c 2 ci PUT 'c' STO
      IF m 4 >
      THEN 3 m 2 -
        FOR i d 2 m
* i - 1 - GET 'd1'
STO d i GET 'd2'
STO
          IF z d1 <
          THEN 1
'x' STO
          ELSE 0
'x' STO
          END p1 i
1 + x PUT 'p1' STO
p1 l1 i - x PUT
'p1' STO d1 z - 1 -
10 MOD 'y' STO p2 i
y PUT l2 i - 1 + y
PUT 'p2' STO d2 p1
i GET - y - ci - 10
MOD 'z' STO p3 i z
PUT 'p3' STO p3 l3
i - 1 + z PUT 'p3'
STO p1 i GET y + z
+ ci + d2 - 10 / IP
'ci' STO c i ci PUT
'c' STO
        NEXT
      END d m GET
'd1' STO d m 1 -
GET 'd2' STO
      IF z d1 <
      THEN p1 m 1
PUT 'p1' STO p1 m 1
+ 1 PUT 'p1' STO
      ELSE p1 m 0
PUT 'p1' STO p1 m 1
+ 0 PUT 'p1' STO
      END d1 z - 1
- 10 MOD 'y' STO p2
m 1 - y PUT m y PUT
'p2' STO d2 p1 m 1
- GET - y - ci - 10
MOD 'z' STO p3 m 1
- z PUT 'p3' STO x
y + z + ci + 10 /
IP 'ci' STO c m 1 -
ci PUT 'c' STO
      IF p1 m GET c
m 1 - GET + 0 == p2
m 1 - GET 9 ‹ AND
      THEN
        IF p3 m 1 -
GET 0 ‹
        THEN p2 m
GET 1 + 'y' STO p2
m y PUT m 1 - y PUT
'p2' STO p3 m 1 -
GET 1 - 'z' STO p3
m 1 - z PUT 'p3'
STO
        ELSE
          IF p2 m 2
- GET 0 ‹
          THEN p2 m
1 + GET 1 - 'y' STO
p2 m 1 + y PUT 'p2'
STO p2 m 2 - y PUT
'p2' STO
            IF p2 m
1 - GET 1 ‹ p3 m 2
- GET 9 ‹ AND
            THEN p1
m 1 + 1 PUT 'p1'
STO p1 m 1 PUT 'p1'
STO p2 m GET 1 -
'y' STO p2 m y PUT
m 1 - y PUT 'p2'
STO p3 m GET 1 +
'z' STO p3 m z PUT
m 2 - z PUT m 1 - 1
PUT 'p3' STO
            ELSE
              IF p2
m 1 - GET 1 ‹
              THEN
p1 m 1 + 2 PUT 'p1'
STO p1 m 2 PUT 'p1'
STO p2 m GET 2 -
'y' STO p2 m y PUT
m 1 - y PUT 'p2'
STO p3 m 0 PUT m 2
- 0 PUT 'p3' STO p3
m 1 - 3 PUT 'p3'
STO
              ELSE
p1 m 1 + 1 PUT 'p1'
STO p1 m 1 PUT 'p1'
STO p2 m 9 PUT m 1
- 9 PUT 'p2' STO p3
m 0 PUT m 2 - 0 PUT
m 1 - 3 PUT 'p3'
STO
              END
            END
          ELSE
            IF p3 m
1 - GET 0 == p2 m 2
- GET - == AND
            THEN p1
m 2 + GET 1 - 'x'
STO p1 m 2 + x PUT
'p1' STO p1 m 1 - x
PUT 'p1' STO
              IF p3
m 2 - GET 9 ‹
              THEN
p1 m 1 + 1 PUT 'p1'
STO p1 m 1 PUT 'p1'
STO p2 m 1 + 9 PUT
m 2 - 9 PUT m GET 1
- 'y' STO p2 m y
PUT m 1 - y PUT
'p2' STO p3 m GET 1
+ 'z' STO p3 m z
PUT m 2 - z PUT m 1
- 1 PUT 'p3' STO
              ELSE
IF p2 m 1 - GET 1 ‹
THEN p1 m 1 + 2 PUT
'p1' STO p1 m 2 PUT
'p1' STO p2 m 1 + 9
PUT m 2 - 9 PUT m
GET 2 - 'y' STO p2
m y PUT m 1 - y PUT
'p2' STO p3 m 0 PUT
'p3' STO p3 m 1 - 3
PUT m 2 - 0 PUT
'p3' STO
ELSE p1 m 1 + 1 PUT
'p1' STO p1 m 1 PUT
'p1' STO p2 m 1 + 9
PUT m 9 PUT m 1 - 9
PUT 'p2' STO p2 m 2
- 9 PUT 'p2' STO p3
m 0 PUT m 1 - 3 PUT
m 2 - 0 PUT 'p3'
STO
END
              END
            END
          END
        END
      ELSE
        IF p1 m GET
c m 1 - GET + 0 ==
        THEN p1 m 1
+ 1 PUT 'p1' STO p1
m 1 PUT 'p1' STO p2
m 1 + GET 1 - 'y'
STO p2 m 1 + y PUT
m 2 - y PUT 'p2'
STO p2 m 8 PUT m 1
- 8 PUT 'p2' STO p3
m GET 1 + 'z' STO
p3 m z PUT m 2 - z
PUT m 1 - 1 PUT
'p3' STO
        ELSE
          IF p1 m
GET c m 1 - GET + 2
== p1 m GET 0 ==
AND
          THEN
            IF p3 m
1 - GET 9 ‹
            THEN p2
m GET 1 - 'y' STO
p2 m y PUT m 1 - y
PUT 'p2' STO p3 m 1
- GET 1 + 'z' STO
p3 m 1 - z PUT 'p3'
STO
            ELSE
              IF p3
m 2 - GET 9 ‹
              THEN
p1 m 1 PUT m 1 + 1
PUT 'p1' STO p2 m
GET 2 - 'y' STO p2
m y PUT m 1 - y PUT
'p2' STO p3 m GET 1
+ 'z' STO p3 m z
PUT m 2 - z PUT m 1
- 1 PUT 'p3' STO
IF p2 m 2 - GET 0 ‹
THEN p2 m 1 + GET 1
- 'y' STO p2 m 1 +
y PUT m 2 - y PUT
'p2' STO
ELSE p1 m 1 - GET 1
- 'x' STO p1 m 2 +
x PUT m 1 - x PUT
'p1' STO p2 m 1 + 9
PUT m 2 - 9 PUT
'p2' STO
END
              ELSE
IF p2 m 1 - GET 7 ‰
THEN p1 m 1 + 8 PUT
'p1' STO p1 m 8 PUT
'p1' STO p2 m GET 2
+ 'y' STO p2 m y
PUT m 1 - y PUT
'p2' STO p3 m 8 PUT
m 1 - 8 PUT 'p3'
STO p3 m 2 - 8 PUT
'p3' STO
  IF p2 m 2 - GET 9

  THEN p1 m 2 + GET
1 - 'x' STO p1 m 2
+ x PUT m 1 - x PUT
'p1' STO p2 m 1 +
GET 1 + 'y' STO p2
m 1 + y PUT 'p2'
STO p2 m 2 - y PUT
'p2' STO
  ELSE p2 m 1 + 0
PUT m 2 - 0 PUT
'p2' STO
  END
ELSE p1 m 1 + 2 PUT
'p1' STO p1 m 2 PUT
'p1' STO p2 m GET 3
- 'y' STO p2 m y
PUT m 1 - y PUT
'p2' STO p3 m 0 PUT
m 1 - 3 PUT 'p3'
STO p3 m 2 - 0 PUT
'p3' STO
  IF p3 m 2 - GET 1
Š
  THEN p2 m 1 + GET
1 - 'y' STO p2 m 1
+ y PUT m 2 - y PUT
'p2' STO
  ELSE p1 m 2 + GET
1 - 'x' STO p1 m 2
+ x PUT m 1 - x PUT
'p1' STO p2 m 1 + 9
PUT m 2 - 9 PUT
'p2' STO
  END
END
              END
            END
          ELSE
            IF p1 m
GET c m 1 - GET + 2
== p1 m GET 1 ==
AND
            THEN
              IF p3
m 1 - GET 9 ‹ p2 m
1 - GET 0 ‹ AND
              THEN
p2 m GET 1 - 'y'
STO p2 m y PUT m 1
- y PUT 'p2' STO p3
m 1 - GET 1 + 'z'
STO p3 m 1 - z PUT
'p3' STO
              ELSE
IF p3 m 1 - GET 9 ‹
p2 m 1 - GET 0 ==
AND
THEN p1 m 0 PUT
'p1' STO p1 m 1 + 0
PUT 'p1' STO p2 m 9
PUT m 1 - 9 PUT
'p2' STO p3 m 1 -
GET 1 + 'z' STO p3
m 1 - z PUT 'p3'
STO
ELSE
  IF p3 m 1 - GET 9
== p3 m 2 - GET 0 ‹
AND
  THEN
    IF p2 m 2 - GET
9 ‹
    THEN p1 m 1 + 0
PUT m 0 PUT 'p1'
STO p2 m 1 + GET 1
+ 'y' STO p2 m 1 +
y PUT m 2 - y PUT
'p2' STO p2 m GET 1
+ 'y' STO p2 m y
PUT m 1 - y PUT
'p2' STO p3 m GET 1
- 'z' STO p3 m z
PUT m 2 - z PUT m 1
- 8 PUT 'p3' STO
    ELSE
      IF p2 m 1 -
GET 1 >
      THEN p1 m 1 +
2 PUT m 2 PUT 'p1'
STO p2 m GET 2 -
'y' STO p2 m y PUT
'p2' STO p2 m 1 - y
PUT m 1 + 8 PUT m 2
- 8 PUT 'p2' STO p3
m GET 1 + 'z' STO
p3 m z PUT m 2 - z
PUT m 1 - 1 PUT
'p3' STO
      ELSE
        IF p2 m 1 -
GET 1 ==
        THEN p1 m 1
+ 1 PUT m 1 PUT
'p1' STO p2 m 1 + 8
PUT m 8 PUT m 1 - 8
PUT 'p2' STO p2 m 2
- 8 PUT 'p2' STO p3
m GET 1 + 'z' STO
p3 m z PUT m 2 - z
PUT 'p3' STO p3 m 1
- 1 PUT 'p3' STO
        ELSE p1 m 1
+ 1 PUT m 1 PUT
'p1' STO p2 m 1 + 8
PUT m 9 PUT m 1 - 9
PUT 'p2' STO p2 m 2
- 8 PUT 'p2' STO p3
m GET 1 + 'z' STO
p3 m z PUT m 2 - z
PUT 'p3' STO p3 m 1
- 1 PUT 'p3' STO
        END
      END
    END
  ELSE
    IF p3 m 1 - GET
9 == p3 m 2 - GET 0
== AND p2 m 2 - GET
0 ‹ AND
    THEN p2 m 1 +
GET 1 - 'y' STO p2
m 1 + y PUT m 2 - y
PUT 'p2' STO p3 m 1
PUT m 1 - 1 PUT
'p3' STO p3 m 2 - 1
PUT 'p3' STO
      IF p2 m 1 -
GET 1 >
      THEN p1 m 1 +
2 PUT m 2 PUT 'p1'
STO p2 m GET 2 -
'y' STO p2 m y PUT
'p2' STO p2 m 1 - y
PUT 'p2' STO
      ELSE
        IF p2 m 1 -
GET 1 ==
        THEN p1 m 1
+ 1 PUT m 1 PUT
'p1' STO p2 m 8 PUT
m 1 - 8 PUT 'p2'
STO
        ELSE p1 m 1
+ 1 PUT m 1 PUT
'p1' STO p2 m 9 PUT
m 1 - 9 PUT 'p2'
STO
        END
      END
    ELSE p1 m 2 +
GET 1 - 'x' STO p1
m 2 + x PUT m 1 - x
PUT 'p1' STO p3 m 1
PUT m 1 - 1 PUT
'p3' STO p3 m 2 - 1
PUT 'p3' STO
      IF p2 m 1 -
GET 1 >
      THEN p1 m 1 +
2 PUT m 2 PUT 'p1'
STO p2 m 1 + 9 PUT
m 2 - 9 PUT m GET 2
- 'y' STO p2 m y
PUT m 1 - y PUT
'p2' STO
      ELSE
        IF p2 m 1 -
GET 0 ==
        THEN p1 m 1
+ 1 PUT m 1 PUT
'p1' STO p2 m 1 + 9
PUT m 2 - 9 PUT m 8
PUT 'p2' STO p2 m 1
- 8 PUT 'p2' STO
        ELSE p1 m 1
+ 1 PUT m 1 PUT
'p1' STO p2 m 1 + 9
PUT m 2 - 9 PUT m 9
PUT 'p2' STO p2 m 1
- 9 PUT 'p2' STO
        END
      END
    END
  END
END
              END
            ELSE
              IF p1
m GET c m 1 - GET +
3 ==
              THEN
p2 m GET 1 - 'y'
STO p2 m y PUT m 1
- y PUT 'p2' STO p3
m 1 - 0 PUT 'p3'
STO
              END
            END
          END
        END
      END p1 NL→I
p2 NL→I p3 NL→I
    »
  »
»
Find all posts by this user
Quote this message in a reply
03-04-2023, 02:13 PM
Post: #42
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Sorry, Gerald. There was a bug (same one in several places in ALGO4) caused by my poor attempt at premature optimization.

I have corrected the code and updated the original post.

I think all is OK now. I have tested numbers that execute almost all paths through ALGO4 - the only remaining untested paths are IV.iii and IV.vi. I could not find numbers that would execute these bits.

I must have been tired / sleepy when I typed in the original given the number of corrections I've made.

Sudhir
Find all posts by this user
Quote this message in a reply
03-04-2023, 05:33 PM (This post was last modified: 05-03-2023 06:29 AM by Gerald H.)
Post: #43
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Fewer errors ... but

For input

126189874318615808
The programme returns

120111001100111021
5878186006818785
200686111686002

Which sums to

126189873218615808
Find all posts by this user
Quote this message in a reply
03-04-2023, 06:05 PM (This post was last modified: 03-15-2023 07:43 PM by Albert Chan.)
Post: #44
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
(03-03-2023 10:57 AM)Gerald H Wrote:  I believe ALGO5 is not necessary.

Removing ALGO5 & eg

12267420107203532444

is correctly partitioned, although differently than in the proof by Cilleruelo.

It may not be necessary for this particular number, but we want to be safe in general.
With center 0, it may lead to a palindrome with invalid center, which may be messy to fix.

I like my simpler "palindrome" pair algorithm.

At the center, there are less special cases to consider.
If no carry, center cell is always vaild = (0 .. 9) - (0 .. 9) = (-9 .. 9)
Even with carry, if (n-y) center is not 0 or 9, we are also safe: (1 .. 8) - (0 .. 9) ± 1 = (-9 .. 9)

Only 2 cases may lead to problem: (n-y) - x = z + (non-zero carry)

0 - 9 = (−10) + 1
9 - 0 = (+10) − 1

To get into these situations are rare. Almost always, no backtracking fix needed.

Here is an example that generated invalid center (±10), required backtracking to fix.
NOTE: n is quoted number, but with center adjusted, to purposely get into trouble.

n = 12267420150203532444 (20 digits)
y = 10^19 - 1 (we always pick odd digits y)

(n-y) also 19 digits, so we search for n = (x+y, both 19 digits) + (z, 18 digits)      (*)

Code:
n-y 2   2   6   7   4   2   0   1   5   0   2   0   3   5   3   2   4   4   5
x   2  -1   1   4  -4  -4  -9  -1   3 (-10) 3  -1  -9  -4  -4   4   1  -1   2
z       3   5   3   8   6   9   2   2   9   9   2   2   9   6   8   3   5   3
                                        1      -1           1

Except for center, x digits are generated from LHS, without carry, thus always valid.

With (n-y) center = 0 AND (last z = 9) AND (carry = +1), x center is invalid.
There is no need to backtrack a lot. All we needed is to avoid last z = 9.
z center of 229 → 218 is enough, guaranteed valid x center.

Code:
n-y 2   2   6   7   4   2   0   1   5   0   2   0   3   5   3   2   4   4   5
x   2  -1   1   4  -4  -4  -9   0  -6 (-8 )-6   0  -9  -4  -4   4   1  -1   2
z       3   5   3   8   6   9   2   1   8   8   1   2   9   6   8   3   5   3
                               -1       0      -1           1

12267420150203532444 = 9899550931390559989 + 2014000000000004102 + 353869218812968353

(*) We only switch to n = x + (y+z) if (n-y) > y (i.e. balance with more digits)
Otherwise, we do n = (x+y) + z, pad with zeroes if necessary.

Above example, n of 122... changed to 100...
Code:
                               7998995386835998997
  10067420150203532444       + 1460210000000120641
-  9999999999999999999       +  608214763367412806
----------------------  -->  ---------------------
   0067420150203532445        10067420150203532444

    0   0   6   7   4   2   0   1   5   0   2   0   3   5   3   2   4   4   5
x  -1   4   6  -1   2   1  -4  -6  -1 (-3) -1  -6  -4   1   2  -1   6   4  -1
z       6   0   8   2   1   4   7   6   3   3   6   7   4   1   2   8   0   6
    1                                                           1
Find all posts by this user
Quote this message in a reply
03-04-2023, 07:05 PM
Post: #45
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Please remember, Albert, that the proof delivers an algorithm for any larger counting system base - some parts may only be required for bases other than 10.
Find all posts by this user
Quote this message in a reply
03-05-2023, 02:56 AM
Post: #46
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
(03-04-2023 05:33 PM)Gerald H Wrote:  Fewer errors ... but

For input

126189874318615808

The programme returns

120111001100111021
5878186006818785
200686111686002

Which sums to

126189873218615808

Aargh! This was caused by an inadvertent deletion of two lines that set the two central digits in the first palindrome to two (120111001100111021) in my "fixed" version yesterday. I have updated the original post with those two lines restored - I honestly hope there are no more mistakes.

Sudhir
Find all posts by this user
Quote this message in a reply
03-05-2023, 11:00 AM
Post: #47
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
In post #28 you forgot to mention LPOP.
Find all posts by this user
Quote this message in a reply
03-05-2023, 11:31 AM
Post: #48
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
I now dismiss removing ALGO5 - it is necessary for cetain base 10 numbers.
Find all posts by this user
Quote this message in a reply
03-09-2023, 04:53 AM
Post: #49
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
On the other hand, I haven't found a number that gets to the "B7" branch of programme "NTYPE" - Has anyone found such a number?
Find all posts by this user
Quote this message in a reply
03-09-2023, 08:23 PM
Post: #50
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Yes, ther are numbers of form "B7", but this form is subsumed under "B2", consequently the programme returns a correct partition via "B2", the form of the partition is as described for "B7".

Either "B7" is redundant or could be placed before "B2" to catch some numbers.

All in all, "B7" is redundant.
Find all posts by this user
Quote this message in a reply
03-09-2023, 11:15 PM
Post: #51
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Type B7 is indeed wholly contained in type B2. Type B4 also overlaps with type B6, with the overlap making up half the numbers in type B4 (those with \(\delta_{l-3}=3\), to be precise).

The declaration of \(x_1, y_1, z_1\) between types B7 and B2 is also compatible, so you can just treat B7 as a special case of B2. Types B6 and B1 are similarly compatible (even though they are merely adjacent, not overlapping). But merging them makes stating the conditions for the combined type quite messy, so that may not be worth doing (it is worth it in my implementation, but not by a lot).

The overlap between types B4 and B6 is not as pretty. You will get different results depending on which one you give preference, because their \(x_1, y_1, z_1\) declarations are different. This is one of two places I saw so far where the proof's algorithm lets you pick between multiple outcomes, the other being the cases in 6-digit numbers where it explicitly tells you to choose \(x_1, y_1\) or \(x_2, y_2\) or \(x_3, y_3\) within some constraints (which are a set of allowed digits (all, or all except zero), and the sum of the pair).

---

My SysRPL implementation is progressing much slower than I anticipated. It's still missing a few cases in 6-digit numbers and a whole lot of testing (and the bugfixes resulting from that). In its incomplete state it's a standalone library weighing just about 3.6 KiB though, so I'm at least winning the code size race against the UserRPL one. Wink On the other hand, there's no way to beat the backtracking-based one in that.
Find all posts by this user
Quote this message in a reply
03-10-2023, 02:15 AM (This post was last modified: 03-12-2023 01:24 AM by 2old2randr.)
Post: #52
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Hi 3298,

(03-09-2023 11:15 PM)3298 Wrote:  My SysRPL implementation is progressing much slower than I anticipated. It's still missing a few cases in 6-digit numbers and a whole lot of testing (and the bugfixes resulting from that).

Attached is an updated set of User RPL programs that use the algorithms in the paper for all numbers including those with 2-6 digits (in SML2-SML6). I've tested all numbers exhaustively up to 199999 so there are no bugs in the code specific to the 2-6 digit cases. Algo2 has been modified to handle the callback from SML6 for numbers that don't begin with 1 in case the 6-digit no. is a "special" number (case II.2.ii.c). I have not tested exhaustively beyond 200000 since I am running the code on a physical 50g and it takes a long time to do so.

I am very curious to see how much smaller / faster your SysRPL version turns out to be. I have been trying to learn SysRPL but it has been pretty heavy going so far.

Sudhir

Attachment removed since there was an additional case that was not covered by the paper I was referring to - the fixed code (as per the later version of the paper) is attached to a later post
Find all posts by this user
Quote this message in a reply
03-10-2023, 10:15 AM
Post: #53
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Your programme, 2old2randr, for input

109025

returns

99299
9090
636

The sum is correct. Have I transcribed programme erroneously?
Find all posts by this user
Quote this message in a reply
03-10-2023, 11:43 AM (This post was last modified: 03-10-2023 11:45 AM by 3298.)
Post: #54
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
You're evil picking such an input number, you know that? Wink

While I haven't looked at the UserRPL program, from the proof alone I can see that it runs into one of the mentioned choose-numbers cases in the 6-digit algorithm. There it apparently disregards the non-zero digit restriction and chooses \(x_1=9\) and \(y_1=0\), causing the y palindrome to become invalid.

To fix it, I recommend implementing the "choose" part as picking (sum / 2) and (sum / 2) + (sum mod 2). As long as the sum is >=2, the chosen digits will be >=1 as well. If it isn't, the restriction can't be fulfilled anyway, and the proof obviously takes care to avoid such failures.
There are no other digit restrictions for these, so you're safe as long as you avoid accidental zeroes.

In UserRPL, the implementation could look like:
Code:
2. IDIV2 OVER +
In SysRPL it depends on the type of number you're calculating with, but it'll be a variation on the same theme - I'm using BINTs, which leads to:
Code:
BINT2 #/ SWAPOVER #+
Note that #2/ exists, but doesn't leave the remainder behind, only the quotient, so it's not suitable. Alternatively, I could do:
Code:
DUP#1+ #2/ SWAP #2/
With ZINTs instead of BINTs you'd be looking at the guts of the UserRPL command, which is appropriately named FPTR2 ^IDIV2. (We definitely don't need to handle complex numbers or symbolics here, so the extra code in FPTR2 ^STEPIDIV2 is dead weight.)
Find all posts by this user
Quote this message in a reply
03-10-2023, 12:40 PM
Post: #55
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
(03-10-2023 11:43 AM)3298 Wrote:  While I haven't looked at the UserRPL program, from the proof alone I can see that it runs into one of the mentioned choose-numbers cases in the 6-digit algorithm. There it apparently disregards the non-zero digit restriction and chooses \(x_1=9\) and \(y_1=0\), causing the y palindrome to become invalid.

That is exactly correct - I've handled it correctly in other positions but not for x1 and y1. I'll fix it on the weekend.

Sudhir
Find all posts by this user
Quote this message in a reply
03-10-2023, 07:12 PM
Post: #56
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Your current SML2 programme, 2old2randr, looks like this in Sys:

Code:
Size: 253.5

CkSum: # 47759d

::
  CK2&Dispatch
  # FF5
  ::
    INCOMPDROP
    COERCE2
    {
      LAM d1
      LAM d0
    }
    BIND
    FPTR2 ^Z>#
    ::
      DUP
      BINT10
      EQUALcasedrp
      ::
        BINT9
        BINT1
        BINT0
      ;
      LAM d1
      LAM d0
      #=case
      ZEROZERO
      DROP
      LAM d1
      LAM d0
      #<case
      ::
        LAM d1
        BINT10
        #*
        LAM d1
        #+
        LAM d0
        LAM d1
        #-
        BINT0
      ;
      LAM d1
      LAM d0
      #1+
      #>case
      ::
        LAM d1
        #1-
        BINT10
        #*
        LAM d1
        #+
        #1-
        BINT10
        LAM d0
        #+
        LAM d1
        #-
        #1+
        BINT0
      ;
      LAM d0
      BINT10
      #*
      LAM d0
      #+
      BINT9
      BINT1
    ;
    ABND
    BINT3
    ZERO_DO
    ROT
    FPTR2 ^#>Z
    LOOP
  ;
;
Find all posts by this user
Quote this message in a reply
03-11-2023, 05:10 AM
Post: #57
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
(03-10-2023 07:12 PM)Gerald H Wrote:  Your current SML2 programme, 2old2randr, looks like this in Sys:

Thank you Gerald, much appreciated. I will try to see if I can come up with a similar program on my own if I write it from scratch in SysRPL.

I've corrected the bug in SML6 w.r.t. the choices of x1 and y1 and updated the attachment in my previous post.

I finally did not use 3298's suggested
Code:
 2 IDIV2 OVER +
but rather did it in inelegant fashion i.e.,
Code:
2 / IP 'y' STO

The reason for this is that when calling PALIN from a test harness program, the IDIV2 instruction pops up a choose box with the message 'Purge current variable?'. Choosing ok continues normally but choosing cancel aborts execution with the message 'Mode switch cancelled'. I have no idea why this happens and could not find anything in the AUR that would explain it (the message itself is listed as DE51 in the Appendix).

Sudhir
Find all posts by this user
Quote this message in a reply
03-11-2023, 06:31 AM
Post: #58
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
Your latest edition, 2old2randr, now gives a correct partition of

109025

Well done. I find it commendable that you use the algorithms for small numbers from the proof - Although it would be odd to declare the winner of the competition one who uses a competitor's programme as a sub-programme!

This website

http://www.rnta.eu/cgi-bin/three_palindr...al3algo.py

claims to use the algorithms in the proof but produces a different & correct answer.

I am pleased to assist as much as I can. I remember the problem with "mode switch" from some years ago but have forgotten the solution - perhaps a more knowledgable member can assist?
Find all posts by this user
Quote this message in a reply
03-11-2023, 06:58 AM (This post was last modified: 03-11-2023 07:10 AM by 2old2randr.)
Post: #59
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
(03-11-2023 06:31 AM)Gerald H Wrote:  This website

http://www.rnta.eu/cgi-bin/three_palindr...al3algo.py

claims to use the algorithms in the proof but produces a different & correct answer.

That is because there is a choice in the first digit i.e., the constraint is x1+y1=9. I try to return the three palindromes in descending order i.e., x >= y >= z so I select the value 5 for x1 and 4 for y1. On the website you have pointed to, he has done the reverse.

Sudhir
Find all posts by this user
Quote this message in a reply
03-11-2023, 01:37 PM
Post: #60
RE: Tripartite Palindromic Partition of Integer (HP 50g) Challenge
I always think it might be me, 2old2randr, but your programme for input

3000

returns

3003
-3
0

Have I copied badly?
Find all posts by this user
Quote this message in a reply
Post Reply 




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