rowSwap( is a rarely-used BASIC command. As one might expect, it's used for swapping two rows of a matrix. In DCS it creates an appvar or something, but I'm more interested in the pure BASIC command.

I don't think I've ever used the rowSwap( command, but I'm interested in what uses others find, especially if they don't relate to linear algebra. PT_ said something about Sudoku board generation?
Or for a Rubik's Cube, lets keep that option open as well.
Yea, you can create a sudoku with it (a randomly filled valid sudoku)

First, let's make the basic sudoku:
That is this one:

Code:
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3   A
7 8 9 1 2 3 4 5 6

2 3 1 5 6 4 8 9 7
5 6 4 8 9 7 2 3 1   B
8 9 7 2 3 1 5 6 4

3 1 2 6 4 5 9 7 8
6 4 5 9 7 8 3 1 2   C
9 7 8 3 1 2 6 4 5


  A     B     C

Now you can permutate the lines in block A (both horizontal and vertical), so shuffle a block of 3x9. If you do that in a random order, both horizontally and vertically, you can shuffle the sudoku to become random.
An example
Swap line 1,3 of A horizontal, becomes this:

Code:
7 8 9 1 2 3 4 5 6
4 5 6 7 8 9 1 2 3   A
1 2 3 4 5 6 7 8 9

2 3 1 5 6 4 8 9 7
5 6 4 8 9 7 2 3 1   B
8 9 7 2 3 1 5 6 4

3 1 2 6 4 5 9 7 8
6 4 5 9 7 8 3 1 2   C
9 7 8 3 1 2 6 4 5


  A     B     C

And after that, maybe line 2,3 C vertical. You any order you want, and it will be totally random.

Hope this helps!
It's actually fairly useful, but only in certain programs. For example, my Shades program uses it to eliminate the bottom row of the matrix and move all other rows above it down.
PT_: Now I see how it's possible to preserve the Sudoku property. That's a clever way to scramble, and it looks very fast.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement