Problem 447. swap sign sum & multiply castles
- It is an easy problem, if you know the answer.
- Given a square matrix of NxN ordinary numbers.
- Initially place N identical indistinguishable castles or rooks (chess pieces) on the main diagonal.
- Then keep swapping any two rows or columns to exhaustively enumerate all possible unique patterns of castle formation.
- Not a single castle in any of these formations should be under threat of any other castle,
- only one castle watches over an otherwise empty row and column.
- For each pattern, find the product of all numbers covered by the castles.
- If this pattern was obtained after even number (0,2,4,...) of swaps,
- then add the product to an initially empty accumulator,
- otherwise subtract the product from the accumulator.
- Give the final expected value of the accumulator,
- does not matter whether by hook or by crook,
- but please give a general solution,
- the test suite may be modified soon.
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Zuha Altaf
on 14 Aug 2024
points 3 and 4 are not clear. Can you explain what is meant by castle here? probably a visualization may help better understand the picture in this problem
Christian Schröder
on 15 Aug 2024
@Zuha Altaf "castle" here means a rook, as in the chess piece; the given (square) matrix is also interpreted as an NxN chessboard.
Zuha Altaf
on 16 Aug 2024
@Christian Schröder, this clears the picture a little, thankyou for your explanation.
Solution Comments
Show commentsGroup

Programování - Cody
- 12 Problems
- 466 Finishers
- Find the sum of all the numbers of the input vector
- Maximum value in a matrix
- Make the vector [1 2 3 4 5 6 7 8 9 10]
- Return area of square
- Select every other element of a vector
- Triangle Numbers
- Check if number exists in vector
- Create times-tables
- Determine whether a vector is monotonically increasing
- Roll the Dice!
- Verify Law of Large Numbers
- Solve a System of Linear Equations
Problem Recent Solvers70
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!