필터 지우기
필터 지우기

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