Consider the following problem: Imagine you choose 3 squares out of a 3x3 field. So you can have a line upwords or downwords, two squares downwords and one to the right etc. So let's number every square (see MWE
). Now it is just a mathematicaly problem: $binom(9,3)$
.
But since the squares all look the same, there is no difference between (1,2,3)
and (3,2,1)
and so on. So when we take a look here it is a pretty good solution, but we got the problem with the duplicates.
I thought of writing a python script which exoprts the correct permuations into a .csv
file and then TikZ
or pgfplots
(maybe it can be done there, too) can read the file and solve the "square problem".
So my question is: How can I "cross out" the duplicates in order to get sth. like in the 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}
Output:
(1,3,2)
and(2,3,1)
will all be(1,2,3)
. What am I doing wrong? And to get all inequivalent sorted lists you could just use texwelt.de/wissen/antwort_link/24383, for instance. – user121799 Mar 12 at 17:13(1,3,2)
,(2,3,1)
and(1,2,3)
, the output will look the same. So when I plot all results, I would get these duplicates. I want to display all combinations without the repeating sequences in the form of a grid (so(1,2,3)
got for example the position(1,1)
etc.) It's just a visualisation of all permutations … I hope it's clear now … – current_user Mar 12 at 20:44(1,3,2)
,(2,3,1)
and(1,2,3)
you would only plot(1,2,3)
but suppress the duplicates(1,3,2)
and(2,3,1)
. – user121799 Mar 12 at 20:49