(33s) OEIS A4186: Digits in Descending Order - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (33s) OEIS A4186: Digits in Descending Order (/thread-18859.html) |
(33s) OEIS A4186: Digits in Descending Order - Gerald H - 09-22-2022 03:33 AM 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 RE: (33s) OEIS A4186: Digits in Descending Order - C.Ret - 09-24-2022 07:41 AM 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. RE: (33s) OEIS A4186: Digits in Descending Order - Gerald H - 09-24-2022 11:32 AM 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? RE: (33s) OEIS A4186: Digits in Descending Order - Gerald H - 09-24-2022 11:56 AM OK, I've now replaced DEG with RAD & it works fine - usage clarified. RE: (33s) OEIS A4186: Digits in Descending Order - C.Ret - 09-24-2022 12:44 PM 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. RE: (33s) OEIS A4186: Digits in Descending Order - C.Ret - 09-25-2022 04:18 PM 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 |