(33s) OEIS A4186: Digits in Descending Order
|
09-22-2022, 03:33 AM
Post: #1
|
|||
|
|||
(33s) OEIS A4186: Digits in Descending Order
Takes a natural number from the stack & returns A4186(N) to stack.
Digits of index decreasing. eg Input 10477 returns 77410. I use [i] to represent the built in sign for use of i in indirect addressing to avoid confusion in say IP(LOG((i))) or 5*(i). Suggestions for improvements most welcome. https://oeis.org/A004186 Preserves stack. Code: 1. LBL D |
|||
09-24-2022, 07:41 AM
(This post was last modified: 09-24-2022 12:46 PM by C.Ret.)
Post: #2
|
|||
|
|||
RE: (33s) OEIS A4186: Digits in Descending Order
Hello,
Since I still have no HP-35S, here is a version for an HP-41C without any extra RAM or ROM module: Code: 001 LBL "4186 // real integer input N in register X: [ ][RTN] 1234 [R/S] ... goose ... goose ... goose ... 4321. 10477 [R/S] ... goose ... goose ... goose ... 77410. This is a simplified version from a code published as one of the numerous solutions of the code challenge Re: Misez p'tit, Optimisez - N°85 (L'Algorithme de Kaprekar) on the French Forum Silicium (20 août 2018). A close related code may produce both decreasing and increasing digits sorted integers from the input: Code: X: N=hdebcijadf [ ][RTN] 1342 [R/S] ... goose ... goose ... goose ... 1234. [X<>Y] 4321. 10477 [R/S] ... goose ... goose ... goose ... 1477. [X<>Y] 77410. |
|||
09-24-2022, 11:32 AM
Post: #3
|
|||
|
|||
RE: (33s) OEIS A4186: Digits in Descending Order
Interesting stuff, Ret, thank you.
The last programme you mention works nicely on a 42S - but I don't see the point of line 35? |
|||
09-24-2022, 11:56 AM
Post: #4
|
|||
|
|||
RE: (33s) OEIS A4186: Digits in Descending Order
OK, I've now replaced DEG with RAD & it works fine - usage clarified.
|
|||
09-24-2022, 12:44 PM
(This post was last modified: 09-24-2022 12:46 PM by C.Ret.)
Post: #5
|
|||
|
|||
RE: (33s) OEIS A4186: Digits in Descending Order
Yes, everyone can put whatever they want in step 035 as long as it can be used as a NOP.
Maybe I should have left the original LBL 04 which more clearly indicates a non-operation. This also applies to step 028 of the first program. |
|||
09-25-2022, 04:18 PM
(This post was last modified: 09-25-2022 04:38 PM by C.Ret.)
Post: #6
|
|||
|
|||
RE: (33s) OEIS A4186: Digits in Descending Order
Hello,
This weekend, I found a way to rent a friend's HP-35S along with its owner's manual. What a funny machine! It is with great difficulty that I managed to adapt my second algorithm to it, the one that gives the integers with the numbers sorted in ascending and descending order. Be indulgent, this is my first program on HP-35S; it is it is intended to be used in RPN mode and with the ALL display option. Code: O001 ►LBL O O011 x<>y O021 1 O031 × O041 1 O051▫ STO I It's a bit long code but it has the advantage of using only one label (LBL O). Unlike the HP-41C version, it handles integers up to 12 digits which it temporarily stores in twelve anonymous registers using indirect addressing via the I register. It also uses flag #1 because I couldn't find a simple instruction to reset or reserve the anonymous register range. The flag is used to reset the anonymous registers on the first pass. At the beginning of the code, I put 13 in the anonymous register (13) in order to 'reserve' without surprise the range (1) to (12). It's a bit of a hassle on this machine, isn't it? The keyboard is far too overloaded, I prefer, by far, to use my more sober HP-41C and with better organized registers. 3142 XEQ O ENTER run a few seconds and display 1234 4321 The initial value 3142 is kept in the register N This version clears all the registers. To preserve memory contents, please alter the code with the starter sequence: Code: O001 LBL O |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)