Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to shuffle a matrix

I have a matrix described as below:

1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 0 0
1 0 1 1 1

I want to shuffle it into all the possible combinations, can anybody suggest a method for shuffling the matrix without changing its internal numbers. In my matrix I have 13 ones, the rest zeros and when I shuffle, I want to have these 13 ones in all possible combinations.

like image 365
zen yang Avatar asked Dec 10 '25 09:12

zen yang


1 Answers

I won't give you the code (because then your grade would be mine, right?) but here's an idea:

  • You have 25 values that can be either 0 or 1.
  • Loop from 0 to 2^25 - 1.
  • For each value, count the "1" bits.
  • If the count is 13, turn value into a matrix.
  • Now start optimizing. Maybe a recursive solution could give you results quicker.
like image 147
Jens Avatar answered Dec 11 '25 23:12

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!