Post Reply 
Puzzle - RPL and others
04-29-2021, 07:03 PM (This post was last modified: 04-29-2021 07:12 PM by Allen.)
Post: #22
RE: Puzzle - RPL and others
(04-29-2021 05:16 PM)Albert Chan Wrote:  How does the code work ?

In having fun with different ways to calculate the final SSN, I wanted to play around with as simiple an inner loop as possible.

Here's a more simplified 46-byte solution that's a smaller, faster, and clearer

Code:

00 { 46-Byte Prgm }
01 19
02 STO 01
03 2                   
04 STO 00           initialize varibles
05 STO× 01        ensures first 2 digits are multiple of 2
06 ISG 00
07>LBL 01
08 4
09 RCL 00
10 X!=Y?
11 SIGN
12 SQRT
13 RCL× 00     add digit if not equal 4, else add double the digit
14 RCL 01
15 10              multiply by 10
16 ×
17 ENTER
18 ENTER
19 RCL 00
20 MOD          calculate difference to closest multiple of current digit
21 -                
22 +               add difference to running total
23 STO 01       PRX after this line if you want to see the number being constructed
24 ISG 00
25 X<>Y          NOP
26 RCL 00
27 ×
28 LOG
29 9               terminate with 9 digit number
30 X>Y?
31 GTO 01
32 RCL 01       recall the answer
33 .END.

If you take the central part of this code:
Code:

15 RCL 01
16 10
17 ×
18 ENTER
19 ENTER
20 RCL 00
21 MOD
22 -

it assembles (left to right) a number that is divisible by the numbers 3 through 9. Unfortunately the naive way produces a number that is not pan-digital.

Python Example here:
Code:

m=3
for j in range(2,10):
    m*=10
    m+=j-m%j
    print(m)
    
32
321
3212
32125
321252
3212524
32125248
321252489

With a few small corrections during the process one can trick the calculator to produce correct results using the naive algorithm:

Code:

m=38                             <- start with 38
for j in range(3,10):         <-  start with 3
    m*=10
    m+=j-m%j
    if j==4: m+=j              <-  add 4 if current variable is 4 
    print(m)
    
381
3816
38165
381654
3816547
38165472
381654729

(04-29-2021 05:16 PM)Albert Chan Wrote:  Where does the cubic, 19x³ - 9x² - 27x, comes from ?
Why total start at -9 ? Why total + 18 at the end ?

In my initial larger version, I was looking for a correction factor for the naive approach to make the number pandigital without modifying the actual structure of the program.

381654729 - 321252489 = 60402240

As it turns out, adding the results of the polynomial 19x³ - 9x² - 27x for 2<x<10 was within 18 of the final answer. The rest of the rube-goldberg looking code is byte savings by reusing the constants {-27,-9,19} to either initialize variables, create coefficients, or implement the final offset (+18).

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Puzzle - RPL and others - Gene - 04-22-2021, 06:55 PM
RE: Puzzle - RPL and others - rprosperi - 04-23-2021, 04:21 PM
RE: Puzzle - RPL and others - EdS2 - 04-23-2021, 07:30 AM
RE: Puzzle - RPL and others - Dave Britten - 04-23-2021, 12:06 PM
RE: Puzzle - RPL and others - 3298 - 04-23-2021, 09:17 AM
RE: Puzzle - RPL and others - ijabbott - 04-23-2021, 03:57 PM
RE: Puzzle - RPL and others - Albert Chan - 04-23-2021, 04:08 PM
RE: Puzzle - RPL and others - Albert Chan - 04-27-2021, 12:14 PM
RE: Puzzle - RPL and others - 3298 - 04-23-2021, 09:05 PM
RE: Puzzle - RPL and others - C.Ret - 04-24-2021, 04:40 PM
RE: Puzzle - RPL and others - C.Ret - 04-25-2021, 09:25 AM
RE: Puzzle - RPL and others - Claudio L. - 04-26-2021, 04:56 PM
RE: Puzzle - RPL and others - 3298 - 04-27-2021, 08:16 PM
RE: Puzzle - RPL and others - Albert Chan - 04-28-2021, 02:33 AM
RE: Puzzle - RPL and others - Albert Chan - 04-28-2021, 03:30 AM
RE: Puzzle - RPL and others - 3298 - 04-28-2021, 10:14 PM
RE: Puzzle - RPL and others - Albert Chan - 04-29-2021, 03:25 AM
RE: Puzzle - RPL and others - Allen - 04-28-2021, 08:45 PM
RE: Puzzle - RPL and others - Albert Chan - 04-29-2021, 05:16 PM
RE: Puzzle - RPL and others - Allen - 04-29-2021 07:03 PM
RE: Puzzle - RPL and others - C.Ret - 05-02-2021, 06:40 AM
RE: Puzzle - RPL and others - 3298 - 05-03-2021, 03:43 PM
RE: Puzzle - RPL and others - Albert Chan - 05-04-2021, 03:29 AM
RE: Puzzle - RPL and others - 3298 - 05-04-2021, 06:48 AM
RE: Puzzle - RPL and others - Albert Chan - 05-05-2021, 06:29 PM
RE: Puzzle - RPL and others - 3298 - 05-06-2021, 04:24 PM
RE: Puzzle - RPL and others - Albert Chan - 05-06-2021, 09:09 PM
RE: Puzzle - RPL and others - Albert Chan - 05-07-2021, 10:35 AM
RE: Puzzle - RPL and others - 3298 - 05-07-2021, 04:17 PM
RE: Puzzle - RPL and others - Albert Chan - 05-09-2021, 01:21 AM
RE: Puzzle - RPL and others - 3298 - 05-09-2021, 01:39 PM
RE: Puzzle - RPL and others - Albert Chan - 05-10-2021, 03:57 AM
RE: Puzzle - RPL and others - Albert Chan - 05-07-2021, 02:56 AM
RE: Puzzle - RPL and others - Albert Chan - 05-10-2021, 05:13 PM
RE: Puzzle - RPL and others - 3298 - 05-10-2021, 08:23 PM
RE: Puzzle - RPL and others - Albert Chan - 05-11-2021, 11:58 AM
RE: Puzzle - RPL and others - 3298 - 05-11-2021, 02:14 PM
RE: Puzzle - RPL and others - John Keith - 05-11-2021, 03:55 PM
RE: Puzzle - RPL and others - ijabbott - 05-11-2021, 10:37 PM
RE: Puzzle - RPL and others - Albert Chan - 05-13-2021, 11:38 PM



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