フィルターのクリア

Matrix with no consecutive nearest neighbours

2 ビュー (過去 30 日間)
Duarte Guerreiro
Duarte Guerreiro 2021 年 4 月 28 日
コメント済み: Bruno Luong 2021 年 4 月 28 日
Hello, everyone,
Is there any way to create a matrix (n x n) where the numbers ( from 0 to n) are placed randomly but with the restriction that a number x does not have x+1 or x-1 as a nearest neighbours (considering 8 neighbours...)
Example of failure:
1 2 4
5 3 7
9 10 12
Thank you.
Duarte
  1 件のコメント
Bruno Luong
Bruno Luong 2021 年 4 月 28 日
"Is there any way to create a matrix (n x n) where the numbers ( from 0 to n) "
In your example n is 3 but values are up to 12.
Please explain again correctly

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2021 年 4 月 28 日
For a 3-by-3 assuming you mean the numbers from 0 to 8 or 1 to 9 the answer is no. The center element is 8-connected to all the other elements of the matrix. Even if you put 0, 1, 8, or 9 in the center the elements 1, 2, 7, or 8 must be adjacent to them respectively.
I have not thought much about larger values of n. Try generating a random n-by-n matrix with randperm and reshape and testing if it satisfies the requirement. The diff function will help you at least with the 4-connected elements. If you try a large number of trials and reject them all as violating your criteria, either it's not possible or the number of valid arrangements is very small and you haven't hit one yet.

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by