Post Reply 
Swapping Registers on HP calculators
03-27-2024, 08:05 PM
Post: #3
RE: Swapping Registers on HP calculators
(03-27-2024 12:50 PM)n1msr Wrote:  I have copied the Python algorithm below in case anyone really is curious. For brevity I have not copied any programmed calculator steps. I have highlighted the Python line that does the swap (line 12).

Hi,

You are welcome, but without any proper indentation, your Python code is really hard to read !

Code:
a = ['a', 'b', 'c', 'd']                   # items to be permutated
N = len(a)
p = [num for num in range(N+1)]
i = 1
print(p,a)
while i < N:
    p[i] -= 1
    if i % 2 == 1:
        j = p[i]
    else:
        j = 0
    a[j], a[i] = a[i], a[j]                   # <-- SWAP the ith and jth elements
    print(p,a)                                  # output current permutation
    i = 1
    while p[i] == 0:
        p[i] = i
        i += 1

I hope this helps anyone reading this thread...

I didn't quite understand the question, are you wondering if there are X<> IND _ _ or x<> (i) instructions on machines other than the HP-41C and HP-15C?

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


Messages In This Thread
RE: Swapping Registers on HP calculators - C.Ret - 03-27-2024 08:05 PM



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