Show all digits of a huge integer

General discussion about calculators, SwissMicros or otherwise
User avatar
Jaymos
Posts: 1635
Joined: Sun Nov 04, 2018 7:03 pm
Location: Cape Town

Re: Show all digits of a huge integer

Post by Jaymos »

rudi wrote:
Thu Jan 26, 2023 7:16 pm
Nice one Jaymos.
First, I wanted to make a matrix with a 10 column row for each group of 10 digits, but found out, that there’s not enough RAM to make a 10x100 matrix.
Then I wanted to simply make a long string and use that to store all digits, but strings can not be 1000 chars long.
I have another idea, hope I get the time to implement it, but right now, there’s something else taking my attention, clear skies and C/2022 E3 (ZTF) 😀
Do try one of your plans after you've seen the comet!

I would like to see better ways - I am not a very good RPN programmer, I would like to see a real efficient program.

Also post a pic of the comet, please!
Jaco Mostert
Elec Eng, South Africa
https://47calc.com C47 (s/n 03818 & 06199), WP43 (0015). In box: HP42S, HP32Sii, WP34S&C, HP28C, HP35s, EL-506P, EL-W506, PB700; ex: FX702P, 11C, HP67 & HP85; iOS: 42s Byron, Free42+, WP31S/34S, HCalc.
User avatar
rudi
Posts: 415
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: Show all digits of a huge integer

Post by rudi »

Jaymos wrote:
Thu Jan 26, 2023 7:34 pm
rudi wrote:
Thu Jan 26, 2023 7:16 pm
Nice one Jaymos.
First, I wanted to make a matrix with a 10 column row for each group of 10 digits, but found out, that there’s not enough RAM to make a 10x100 matrix.
Then I wanted to simply make a long string and use that to store all digits, but strings can not be 1000 chars long.
I have another idea, hope I get the time to implement it, but right now, there’s something else taking my attention, clear skies and C/2022 E3 (ZTF) 😀
Do try one of your plans after you've seen the comet!

I would like to see better ways - I am not a very good RPN programmer, I would like to see a real efficient program.

Also post a pic of the comet, please!
Totally off topic, I tried last week, through holes in the clouds. Just pointed the telescope up in the clouds pointing at the comet, an started taking pictures.

Just 10 of the images showed the comet, the rest was clouds.
https://www.dropbox.com/s/mi19lp1hm34zl ... .jpg?raw=1

Here’s a timelapse showing the challenging weather conditions:
https://www.youtube.com/watch?v=TWjFKFsvDo8

Sorry for this off topic post, but You asked Jaymos ;-)

I’m going to bed early today, there should be clear skies some time after midnight
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
User avatar
akaTB
Posts: 794
Joined: Tue May 02, 2017 1:56 pm
Location: Milan, Italy

Re: Show all digits of a huge integer

Post by akaTB »

rudi wrote:
Thu Jan 26, 2023 7:16 pm
I have another idea, hope I get the time to implement it, but right now, there’s something else taking my attention
Then take a note on the margin of the screen, but be sure there's enough space to fit it in. ;)
Greetings,
    Massimo
ajcaton
-+×÷ left is right and right is wrong :twisted: Casted in gold
User avatar
Jaymos
Posts: 1635
Joined: Sun Nov 04, 2018 7:03 pm
Location: Cape Town

Re: Show all digits of a huge integer

Post by Jaymos »

rudi wrote:
Thu Jan 26, 2023 7:54 pm
Sorry for this off topic post, but You asked Jaymos ;-)
I'm happy - thanks! nice.
Jaco Mostert
Elec Eng, South Africa
https://47calc.com C47 (s/n 03818 & 06199), WP43 (0015). In box: HP42S, HP32Sii, WP34S&C, HP28C, HP35s, EL-506P, EL-W506, PB700; ex: FX702P, 11C, HP67 & HP85; iOS: 42s Byron, Free42+, WP31S/34S, HCalc.
User avatar
pauli
Posts: 251
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Show all digits of a huge integer

Post by pauli »

I fiddled a bit last night until the emulator randomly exited, so nothing concrete yet.

The zero problem can be avoided by using FIX display and storing the digits in the fractional part or using integer mode with leading zeros enabled.

It should be possible to get thirty or more digits per register too.
dlachieze
Posts: 613
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: Show all digits of a huge integer

Post by dlachieze »

Jaymos wrote:
Thu Jan 26, 2023 6:58 pm
My second try after independently seeing the zeroes issue: 105 bytes, 38 steps.

Code: Select all

01 LBL ‘SPLIT’
02 34
03 10^X
04 STO 00
05 DROP
06 2
07 STO 01
08 DROP
09 LBL ‘LL’
10 ENTER
11 RCL 00
12 MOD
13 XEQ ‘->SS’
14 INC 01
15 -
16 RCL 00
17 IDIV
18 X ≠ ? 0.
19 GTO ‘LL’
20 𝑎 ‘END REG ‘
21 RCL 01
22 +
23 STO ->01
24 RTN
25 LBL ‘->SS’
26 ENTER
27 RCL 00
28 +                //Add 10^34 to preserve the zeroes
29 𝑎 ‘ ‘
30 +                //Add a space to convert to string
31 1
32 𝑎SL Y
33 𝑎SR Y
34 DROP
35 STO ->01
36 DROP
37 RTN
38.END.

To view it, you have to press g[REGS] 02, to make the register browser start at 2. The register after the last one will contain the end pointer and the X register ends with the same end pointer.
This is a very nice program, but it doesn’t work on the WP43 due to the ENTER instructions at steps 10 and 26 which disable stack lift.
Jaymos wrote:
Thu Jan 26, 2023 7:34 pm
I would like to see better ways - I am not a very good RPN programmer, I would like to see a real efficient program.
There may be better ways to split the digits, but with the WP43/C43 instruction set your program can be made shorter to 73 bytes, 26 steps and working on the WP43.
The results start at register 00.

Code: Select all

01 LBL ‘SPLIT’
02 LocR 02
03 34
04 10^x
05 STO .00
06 DROP

07 RCL X
08 RCL .00
09 MOD

10 STO- Y
11 RCL+ .00         //Add 10^34 to preserve the zeroes
12 𝑎 ‘‘
13 +                //Add an empty string to convert to string
14 1
15 𝑎SL Y
16 DROP
17 STO ->.01

18 INC .01
19 DROP
20 SDR 34
21 X ≠ ? 0.
22 BACK 015

23 𝑎 ‘END REG ‘
24 RCL+ .01
25 STO ->.01
26 END
DM42: 00425 - DM41X: β00066 - WP43: 00042
User avatar
Jaymos
Posts: 1635
Joined: Sun Nov 04, 2018 7:03 pm
Location: Cape Town

Re: Show all digits of a huge integer

Post by Jaymos »

dlachieze wrote:
Thu Jan 26, 2023 11:48 pm

There may be better ways to split the digits, but with the WP43/C43 instruction set your program can be made shorter to 73 bytes, 26 steps and working on the WP43.
The results start at register 00.
Wow, really nice to see all those instructions at work. Also neat without unnecessary register use.

Well done. A massive improvement from 105 bytes, 38 steps to 73 bytes, 26 steps.

I must admit one of those instructions (BACK) I've never seen in use! So we learn!


Can we improve still?
@Pauli, your ideas mentioned sound interesting?


BTW, I already changed the code and documentation to allow REGS and FLGS to be called from within a program to directly display registers or flags. No control of those are possible of course - it is manual control until EXIT. The last instruction in this user program then becomes REGS, and it jumps to the last used location of the register browser.
Jaco Mostert
Elec Eng, South Africa
https://47calc.com C47 (s/n 03818 & 06199), WP43 (0015). In box: HP42S, HP32Sii, WP34S&C, HP28C, HP35s, EL-506P, EL-W506, PB700; ex: FX702P, 11C, HP67 & HP85; iOS: 42s Byron, Free42+, WP31S/34S, HCalc.
User avatar
BINUBALL
Posts: 46
Joined: Fri Jan 28, 2022 3:48 am
Location: South Korea

Re: Show all digits of a huge integer

Post by BINUBALL »

dlachieze wrote:
Thu Jan 26, 2023 11:48 pm
Jaymos wrote:
Thu Jan 26, 2023 6:58 pm
My second try after independently seeing the zeroes issue: 105 bytes, 38 steps.

Code: Select all

01 LBL ‘SPLIT’
02 34
03 10^X
04 STO 00
05 DROP
06 2
07 STO 01
08 DROP
09 LBL ‘LL’
10 ENTER
11 RCL 00
12 MOD
13 XEQ ‘->SS’
14 INC 01
15 -
16 RCL 00
17 IDIV
18 X ≠ ? 0.
19 GTO ‘LL’
20 𝑎 ‘END REG ‘
21 RCL 01
22 +
23 STO ->01
24 RTN
25 LBL ‘->SS’
26 ENTER
27 RCL 00
28 +                //Add 10^34 to preserve the zeroes
29 𝑎 ‘ ‘
30 +                //Add a space to convert to string
31 1
32 𝑎SL Y
33 𝑎SR Y
34 DROP
35 STO ->01
36 DROP
37 RTN
38.END.

To view it, you have to press g[REGS] 02, to make the register browser start at 2. The register after the last one will contain the end pointer and the X register ends with the same end pointer.
This is a very nice program, but it doesn’t work on the WP43 due to the ENTER instructions at steps 10 and 26 which disable stack lift.
Jaymos wrote:
Thu Jan 26, 2023 7:34 pm
I would like to see better ways - I am not a very good RPN programmer, I would like to see a real efficient program.
There may be better ways to split the digits, but with the WP43/C43 instruction set your program can be made shorter to 73 bytes, 26 steps and working on the WP43.
The results start at register 00.

Code: Select all

01 LBL ‘SPLIT’
02 LocR 02
03 34
04 10^x
05 STO .00
06 DROP

07 RCL X
08 RCL .00
09 MOD

10 STO- Y
11 RCL+ .00         //Add 10^34 to preserve the zeroes
12 𝑎 ‘‘
13 +                //Add an empty string to convert to string
14 1
15 𝑎SL Y
16 DROP
17 STO ->.01

18 INC .01
19 DROP
20 SDR 34
21 X ≠ ? 0.
22 BACK 015

23 𝑎 ‘END REG ‘
24 RCL+ .01
25 STO ->.01
26 END
10 STO- Y is unnecessary. Deleting step 10 and change step 22 to BACK 014 gives 1 step less.
S.Korean / HP-50G | fx-570EX | fx-570CW | HP-200LX
User avatar
pauli
Posts: 251
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Show all digits of a huge integer

Post by pauli »

Another saving is avoiding the LocR and using the lettered registers which (I think) start zero filled.
User avatar
rudi
Posts: 415
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: Show all digits of a huge integer

Post by rudi »

Jaymos wrote:
Thu Jan 26, 2023 9:57 pm
rudi wrote:
Thu Jan 26, 2023 7:54 pm
Sorry for this off topic post, but You asked Jaymos ;-)
I'm happy - thanks! nice.
Thx - I'll post any updates about the comet on FB. I vere up several times this night, but overcast all the time...


Well, this challenge is very interesting, several great ideas has emerged.

I'm planning on using the following snippets for my solution, but still, haven't had the time to look at it yet

Code: Select all

// get number of digits of the number in X
LOG
1
+
IP

Code: Select all

// get X'th digit of the number in Y, digits numbered right to left, first digit index=1
1
-
10^x
/
10
MOD
IP
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Post Reply