Properties
Similar Topics
Statistics
Comments
2
Participants
2
Subscribers
2
Votes
1
Views
685
Share

How to exchange elements random in the same row of the matrix list
Answered
How to exchange elements random in the same row of the matrix list given the number of exchanges for each of the rows in the list.
Maybe need nested sequence, randombetween, length and element command, but I dont understand how swap/exchange.
Files:
SwapElement.ggb
- GeoGebra
- Help
- Partners
-
Contact us
- Feedback & Questions
- This email address is being protected from spambots. You need JavaScript enabled to view it.
- +43 677 6137 2693
© 2023 International GeoGebra Institute
Thank you. I solved the problem by adding the shuffle command
==
Sequence(Shuffle(Sequence(If(i ≤ cantV, 1, 0), i, 1, n, 1)), j, 1, n, 1)
A tricky solution with the help of sorting.
l1
for 10 rows, 4 indices (column number) per row are determined with a random number
l2
The 4 indices from l1 are randomly mixed.
l3
Forms the indices in a sequence from 1 to 10. If, however, the current index occurs in the sequence in a certain position of l1, so the index from l2 is taken over with the same position.
l3 is the help list for sorting. It can be interpreted as follows:
The first value (in one line) of m1 receives as new position the first value from l3.
The second value from m1 receives as new position the second value from l3
etc.
I have changed the values in m1 so that they are not confused with the indices.
The result is formed in m2.
-------------------------------
Alternative:
Realize the whole thing as a script.
there is the command SetValue( <List>, <Number>, <Object> )
However, this would require the matrix to be converted into a one-dimensional list
and there is no decent iteration in GGB script. Substitute for this is Execute(< with iteration generated commands>)
In the end it probably will be even more tricky than solution above
Thank you. I solved the problem by adding the shuffle command
==
Sequence(Shuffle(Sequence(If(i ≤ cantV, 1, 0), i, 1, n, 1)), j, 1, n, 1)
Comments have been locked on this page!