Post Reply 
(50G) Digits sum (50g)
04-15-2020, 03:49 AM
Post: #5
RE: Digits sum (50g)
That's an interesting program to experiment with, Juan!

Same answer for base 10, but a completely different method:

Code:
\<<
   R\->I \->STR
   0 SWAP
   WHILE
      DUP SIZE
   REPEAT
      DUP TAIL SWAP HEAD
      NUM 48. -
      ROT +
      SWAP
   END
   DROP
   R\->I
\>>

IDIV2 is very slow, and I usually go out of my way to avoid using it for anything repetitive (which ironically is where it would be most useful). A 2000-digit number passed to your original program takes about 240 seconds to complete on my 50g. That same number passed to the above program finished in about 32 seconds.

The ListExt library contains a couple commands (I→NL, LSUM) which make all of this much easier. In particular, I→NL creates a list whose elements are the individual digits of the original number. LSUM is a more forgiving version of ΣLIST (it also accepts lists with 0 or 1 element):
Code:
\<<
   I\->NL
   LSUM
   R\->I
\>>

It's even faster than the original program above -- a 2000-digit number is summed in about 3 seconds with this code.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(50G) Digits sum (50g) - Juan14 - 04-12-2020, 08:05 PM
RE: Digits sum (50g) - grsbanks - 04-13-2020, 09:45 AM
RE: Digits sum (50g) - Nihotte(lma) - 04-13-2020, 08:38 PM
RE: Digits sum (50g) - Juan14 - 04-13-2020, 11:01 PM
RE: Digits sum (50g) - DavidM - 04-15-2020 03:49 AM
RE: Digits sum (50g) - John Keith - 04-15-2020, 10:21 PM
RE: Digits sum (50g) - DavidM - 04-17-2020, 04:31 AM
RE: Digits sum (50g) - Gerald H - 04-17-2020, 10:42 AM
RE: (50G) Digits sum (50g) - gor1060 - 12-11-2022, 11:15 AM



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