사각형의 순열

사각형의 순열

다음 문제를 생각해 보세요. 3x3 필드에서 3개의 정사각형을 선택한다고 상상해 보세요. 따라서 위쪽 단어 또는 아래쪽 단어, 두 개의 사각형 아래쪽 단어 및 오른쪽에 한 줄 등을 가질 수 있습니다. 따라서 모든 사각형에 번호를 매겨 봅시다(참조 MWE). 이제 그것은 단지 수학적인 문제일 뿐입니다: $binom(9,3)$.

(1,2,3)그러나 정사각형은 모두 동일하게 보이기 때문에 및 (3,2,1)등에 는 차이가 없습니다 . 그래서 우리가 살펴볼 때여기꽤 좋은 해결책이지만 중복 문제가 발생했습니다.

나는 올바른 순열을 .csv파일로 추출한 다음 TikZ또는 pgfplots(어쩌면 거기에서도 수행될 수 있음) 파일을 읽고 "제곱 문제"를 해결할 수 있는 Python 스크립트를 작성하는 것을 생각했습니다.

그래서 내 질문은: sth를 얻기 위해 중복 항목을 어떻게 "삭제"할 수 있습니까? 에서처럼 MWE?

\documentclass[border=5pt,tikz]{standalone}
\newcommand{\setcircle}[3]{
    \pgfmathsetmacro\testnum{int(mod(#1,3))}
    \ifnum\testnum=0
        \pgfmathsetmacro\oxpos{3}
        \pgfmathsetmacro\oypos{floor(#1/3)-1}
    \else
        \pgfmathsetmacro\oxpos{mod(#1,3)}
        \pgfmathsetmacro\oypos{floor(#1/3)}
    \fi

    \pgfmathsetmacro\testnum{int(mod(#2,3))}
    \ifnum\testnum=0
        \pgfmathsetmacro\txpos{3}
        \pgfmathsetmacro\typos{floor(#2/3)-1}
    \else
        \pgfmathsetmacro\txpos{mod(#2,3)}
        \pgfmathsetmacro\typos{floor(#2/3)}
    \fi

    \pgfmathsetmacro\testnum{int(mod(#3,3))}
    \ifnum\testnum=0
        \pgfmathsetmacro\thxpos{3}
        \pgfmathsetmacro\thypos{floor(#3/3)-1}
    \else
        \pgfmathsetmacro\thxpos{mod(#3,3)}
        \pgfmathsetmacro\thypos{floor(#3/3)}
    \fi

    \draw (\oxpos,-\oypos) circle(.5) node {#1};
    \draw (\txpos,-\typos) circle(.5) node {#2};
    \draw (\thxpos,-\thypos) circle(.5) node {#3};
}
\begin{document}
    \begin{tikzpicture}
        \foreach \x in {1,...,9}
        {
            \pgfmathsetmacro\testnum{int(mod(\x,3))}
            \ifnum\testnum=0
                \pgfmathsetmacro\xpos{3}
                \pgfmathsetmacro\ypos{floor(\x/3)-1}
            \else
                \pgfmathsetmacro\xpos{mod(\x,3)}
                \pgfmathsetmacro\ypos{floor(\x/3)}
            \fi

            \draw (\xpos,-\ypos) circle(.5) node {\x};
        }

        \begin{scope}[xshift=-3cm,yshift=-4cm]
            \setcircle{1}{2}{5}
        \end{scope}

        \begin{scope}[yshift=-4cm]
            \setcircle{1}{2}{3}
        \end{scope}

        \begin{scope}[xshift=3cm,yshift=-4cm]
            \setcircle{3}{6}{8}
        \end{scope}
    \end{tikzpicture}
\end{document}

산출:

스크린샷

답변1

이렇게 하면 동등하지 않은 조합이 모두 그려집니다.

\documentclass[tikz,border=3.14mm]{standalone}
\newcounter{mystep}
\begin{document}
\begin{tikzpicture}[insert circle/.style={insert path={%
({mod(#1-1,3)*0.75},{int((#1-1)/3)*0.75}) node[circle,draw]{#1}}}]
\foreach \X [evaluate=\X as \Ymin using {int(\X+1)}] in {1,...,9}
{\foreach \Y [evaluate=\Y as \Zmin using {int(\X+1)}]in {\Ymin,...,9}
{\foreach \Z in {\Zmin,...,9}
{\ifnum\X<\Y
   \ifnum\Y<\Z
     \stepcounter{mystep}
     \begin{scope}[xshift={mod(\number\value{mystep}-1,7)*3cm},
     yshift={-int((\number\value{mystep}-1)/7)*3cm}]
      \path[insert circle/.list={\X,\Y,\Z}];
     \end{scope}
   \fi
 \fi  
}}}
\typeout{\number\value{mystep}\space combinations}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보