How to pass by reference in XCAS ?
|
10-26-2020, 01:46 PM
Post: #6
|
|||
|
|||
RE: How to pass by reference in XCAS ?
Another example, in-place permutations of list.
We can swap 2 elements to create another permutation, this involved 3 assignments. x = lst[i]; lst[i] = lst[j]; lst[j] = x; We could reduce above to about 2 assignments, by reusing x. Here is Ive's method, see Permutation Generation Methods, by Robert Sedgewick, page 148-149 Code: def ives(lst, i, j): >>> permute = lambda lst: ives(lst, 0, len(lst)-1) >>> for pat in permute(range(1,6)): print pat ... [1, 2, 3, 4, 5] [2, 1, 3, 4, 5] [2, 3, 1, 4, 5] [2, 3, 4, 1, 5] [2, 3, 4, 5, 1] [1, 3, 4, 5, 2] [3, 1, 4, 5, 2] [3, 4, 1, 5, 2] [3, 4, 5, 1, 2] [3, 4, 5, 2, 1] ... |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
How to pass by reference in XCAS ? - medwatt - 10-26-2020, 03:10 AM
RE: How to pass by reference in XCAS ? - Stevetuc - 10-26-2020, 07:20 AM
RE: How to pass by reference in XCAS ? - Albert Chan - 10-26-2020, 11:17 AM
RE: How to pass by reference in XCAS ? - pinkman - 10-26-2020, 11:43 AM
RE: How to pass by reference in XCAS ? - medwatt - 10-26-2020, 12:31 PM
RE: How to pass by reference in XCAS ? - Albert Chan - 10-26-2020 01:46 PM
RE: How to pass by reference in XCAS ? - parisse - 10-27-2020, 07:32 AM
RE: How to pass by reference in XCAS ? - Albert Chan - 10-27-2020, 08:14 AM
RE: How to pass by reference in XCAS ? - parisse - 10-27-2020, 05:17 PM
|
User(s) browsing this thread: 1 Guest(s)