Looping Through a Nested List
(edit) 2017: since xint 1.1 (2014/10/28)
one needs here \usepackage{xinttools}
. Code updated for that to replace \usepackage{xint}
of initial answer.
I am editing this answer because the 1.09f
release of xint transparently removes all spaces around commas when dealing with comma separated lists. Thus, some of the earlier issues mentioned here are now irrelevant and have been removed.
\documentclass[border=12pt]{standalone}
\usepackage{xinttools} % for \xintFor and \xintFor* loops
% the macro \chisum is also written using an \xintFor loop.
% the math mode dollar signs are in the tabular not in this \chisum
\newcounter{ct}
\def\chisum#1{\def\chisep{\def\chisep{\oplus}}%
\setcounter{ct}{0}%
\xintFor ##1 in {#1}\do % #1 is a comma separated list
{\stepcounter{ct}%
\ifcase ##1
\or \chisep \chi_{\thect}
\else \chisep ##1\chi_{\thect}
\fi}%
}% end of \chisum definition
\newcounter{rowindex}
\begin{document}\thispagestyle{empty}
% ADDED REMARK: since xint 1.09f, spaces around commas are transparently removed.
% This is made a bit extreme here for demonstrative purposes.
\def\decompgirreps{ { 1,0,0,0,0,0,0,0,0,0,0} , {0,1,0,0,0,0,0,0,0,0,0}
,{0,0,1,0,0,0,0,0,0,0,0} ,
{0,0,0,0,0,1,0,0,0,0,0},{0,0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,0,0,0,1,0,0},{1,0,0
,0,0,1,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,1,0},{0,0,0,1,1,0,0,0,0,0,0}, {
0,0,0, 0 ,0 ,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,1},{0,0,0,0,0,1,0,0,0,1,0},{0,1,1,0,0,0,0,0,1,1,0},{0,0,0,0,0,1,0,0,1,1,0},{0,0,0,0,1,0,1,1,0,0,1},{0,0,0,1,0,0,1,1,0,0,1
}}
\setcounter{rowindex}{0}
\begin{tabular}{| c || c | }
\hline $G^4$ Irreps & Decomp into $SL_2^7$ Irreps \\ \hline \hline
\xintFor #1 in \decompgirreps\do {%
\stepcounter{rowindex}
$\mu_{\arabic{rowindex}}$ & $\chisum{#1}$%
\\ \hline
}%
\end{tabular}
\end{document}
Output:
Here is with the original data provided by the researchers:
\documentclass[border=12pt]{standalone}
\usepackage{xinttools} % for \xintFor*
% The original \clebschdata
\def\clebschdata {{{1,0,0,0,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,0,0,0,0},{0,0,1,0,0,0,0,0,0,0,0},{0,0,0,1,0,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,0,0,0},{0,0,0,0,0,1,0,0,0,0,0},{0,0,0,0,0,0,1,0,0,0,0},{0,0,0,0,0,0,0,1,0,0,0},{0,0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,0,0,0,0,1,0},{0,0,0,0,0,0,0,0,0,0,1}},{{0,1,0,0,0,0,0,0,0,0,0},{0,0,1,0,0,1,0,0,0,0,0},{1,0,0,0,0,0,0,0,0,1,0},{0,0,0,0,1,0,0,0,0,0,1},{0,0,0,0,0,0,1,1,0,0,0},{0,0,1,0,0,0,0,0,1,1,0},{0,0,0,1,0,0,1,0,0,0,1},{0,0,0,1,0,0,0,1,0,0,1},{0,0,0,0,0,1,0,0,1,1,0},{0,1,0,0,0,1,0,0,1,1,0},{0,0,0,0,1,0,1,1,0,0,1}},{{0,0,1,0,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,0,0,1,0},{0,1,0,0,0,1,0,0,0,0,0},{0,0,0,0,0,0,1,1,0,0,0},{0,0,0,1,0,0,0,0,0,0,1},{0,1,0,0,0,0,0,0,1,1,0},{0,0,0,0,1,0,1,0,0,0,1},{0,0,0,0,1,0,0,1,0,0,1},{0,0,0,0,0,1,0,0,1,1,0},{0,0,1,0,0,1,0,0,1,1,0},{0,0,0,1,0,0,1,1,0,0,1}},{{0,0,0,1,0,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,0,0,1},{0,0,0,0,0,0,1,1,0,0,0},{0,0,1,0,0,1,0,0,1,0,0},{1,0,0,0,0,0,0,0,1,1,0},{0,0,0,0,1,0,1,1,0,0,1},{0,1,0,0,0,1,0,0,1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},{1,1,1,0,0,1,0,0,1,2,0},{0,0,0,1,1,0,2,1,0,0,2},{0,0,0,1,1,0,2,2,0,0,2},{0,1,1,0,0,2,0,0,2,2,0}},{{0,0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,1,0,0,1,1,0},{0,0,0,0,0,1,0,0,1,1,0},{0,0,0,1,1,0,1,1,0,0,1},{0,0,0,1,1,0,1,1,0,0,1},{0,1,1,0,0,1,0,0,2,2,0},{0,0,0,1,1,0,1,2,0,0,2},{0,0,0,1,1,0,2,1,0,0,2},{1,1,1,0,0,2,0,0,2,2,0},{0,1,1,0,0,2,0,0,2,3,0},{0,0,0,1,1,0,2,2,0,0,3}},{{0,0,0,0,0,0,0,0,0,1,0},{0,1,0,0,0,1,0,0,1,1,0},{0,0,1,0,0,1,0,0,1,1,0},{0,0,0,1,0,0,1,1,0,0,2},{0,0,0,0,1,0,1,1,0,0,2},{0,1,1,0,0,2,0,0,2,2,0},{0,0,0,1,1,0,2,2,0,0,2},{0,0,0,1,1,0,2,2,0,0,2},{0,1,1,0,0,2,0,0,2,3,0},{1,1,1,0,0,2,0,0,3,3,0},{0,0,0,2,2,0,2,2,0,0,3}},{{0,0,0,0,0,0,0,0,0,0,1},{0,0,0,0,1,0,1,1,0,0,1},{0,0,0,1,0,0,1,1,0,0,1},{0,0,1,0,0,1,0,0,1,2,0},{0,1,0,0,0,1,0,0,1,2,0},{0,0,0,1,1,0,2,2,0,0,2},{0,1,1,0,0,2,0,0,2,2,0},{0,1,1,0,0,2,0,0,2,2,0},{0,0,0,1,1,0,2,2,0,0,3},{0,0,0,2,2,0,2,2,0,0,3},{1,1,1,0,0,2,0,0,3,3,0}}}
% the macro \chisum in its original style with some modifications to let it work
\makeatletter
\newcounter{ct}
\def\chisum#1{$\def\zzsep{\def\zzsep{\oplus}}\setcounter{ct}{0}%
\@for\tmp:=#1\do
{\stepcounter{ct}\expandafter\zzz\tmp\relax}$}
\makeatother
% auxiliary macro for the original \chisum
\def\zzz#1\relax{
\ifnum #1=1
\zzsep\chi_{\thect}
\else
\ifnum #1=0
\else
\zzsep#1\chi_{\thect}
\fi
\fi
}
\newcounter{rowindex}
\begin{document}\thispagestyle{empty}
\setcounter{rowindex}{0}
\begin{tabular}{*{12}c}
$\bigotimes$&$\chi_1$&$\chi_2$&$\chi_3$&$\chi_4$&$\chi_5$&$\chi_6$&$\chi_7$&$\chi_8$&$\chi_9$&$\chi_{10}$&$\chi_{11}$ \\
\xintFor #1 in \clebschdata \do {%
\stepcounter{rowindex}
$\chi_{\arabic{rowindex}}$ \xintFor #2 in {#1} \do {&\chisum{#2}}%
\\
}%
\end{tabular}
\end{document}
The image is shown much reduced but if you dragged the image to your desktop it has correct size.
This is my first answer:
\documentclass{article}
\usepackage{xint} % for \xintFor* (needs xint v1.09c)
\usepackage{xintexpr}
% only used because I didn't know what to do with \chisum
%% \usepackage{array} % (not needed here)
% This was the hardest part, generating this:
\def\clebschdata {{{2,1,7,2,9,5,6,0,3,0,2},{1,7,1,1,9,5,1,2,5,8,1},{6,6,1,9,4,1,5,7,3,1,9},{1,9,9,1,4,0,6,7,8,6,5},{2,5,5,5,9,5,2,7,3,7,3},{2,5,8,9,0,5,7,7,4,0,0},{5,5,2,9,2,3,9,8,1,7,5},{7,0,3,0,4,1,0,8,1,8,9},{9,6,6,3,6,6,7,2,5,9,5},{0,4,4,8,1,5,0,1,6,9,9},{2,7,2,7,4,6,4,8,2,5,9}},{{3,4,6,0,0,0,1,0,5,6,5},{4,2,6,4,0,3,0,0,0,5,8},{1,0,9,8,4,5,2,1,6,5,0},{3,1,9,6,0,4,1,4,8,6,9},{0,7,6,7,5,7,8,2,2,8,1},{7,7,9,9,2,2,1,6,8,0,2},{5,4,9,7,8,9,5,7,1,9,2},{4,1,4,0,2,3,8,4,2,6,4},{5,5,8,2,7,7,1,3,1,1,3},{4,5,5,0,7,0,5,2,4,2,2},{1,2,4,0,0,2,8,8,7,8,8}},{{3,2,1,6,8,2,0,1,5,8,8},{3,3,5,7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,9,0,5},{5,6,2,6,9,7,0,0,1,1,7},{9,8,0,5,9,4,8,3,3,5,0},{6,4,8,8,9,3,2,7,1,5,8},{4,2,8,5,6,8,9,1,2,9,9},{3,7,1,3,5,7,1,2,9,0,2},{1,4,6,5,4,2,4,6,4,2,0},{9,6,1,8,0,5,9,8,3,5,5},{3,1,5,2,8,9,9,3,2,9,0},{9,5,4,2,3,4,0,9,4,6,3}}}
\def\chisum #1{\xintthenumexpr sum(#1)\relax}
\newcounter{rowindex}
\begin{document}\thispagestyle{empty}
\setcounter{rowindex}{0}
\begin{tabular}{*{12}c}
$\bigotimes$&$\chi_1$&$\chi_2$&$\chi_3$&$\chi_4$&$\chi_5$&$\chi_6$&$\chi_7$&$\chi_8$&$\chi_9$&$\chi_{10}$&$\chi_{11}$ \\
\xintFor #1 in \clebschdata \do {%
\stepcounter{rowindex}
$\chi_{\arabic{rowindex}}$ \xintFor #2 in {#1} \do {&\chisum{#2}}%
\\
}%
\end{tabular}
\end{document}
Output:
Some info on \xintFor
.
This is a utility from xint (version 1.09c
and later). It is not completely expandable but has some properties of completely expandable macros: nesting, capacity to handle group closing contexts such as inside tabulars (LaTeX) or general alignments. Two forms (the spaces before and after in
, before and after \do
, before the #1
, are optional):
\xintFor #1 in {a,b,c} \do {stuff with #1=a then b then c}
\xintFor* #1 in {{a}{b}{c}} \do {stuff with #1=a then b then c}
In the first form, spaces at the start of the list, around commas, and at the end are transparently removed since release 1.09f
.
In the second form, spaces separating braced items do not count. Spaces inside each individual braced item are significant.
One can write \xintFor #1 in \Tmp \do {stuff}
or equivalently \xintFor #1 in {\Tmp} \do {stuff}
. But \Tmp
must expand in one step to a comma separated list.
With \xintFor*
it is slightly different, \Tmp
is expanded again and again until hitting a brace or something unexpandable at the beginning. So \def\x{{a}{b}{c}}\def\y{\x}\xintFor* #1 in \y \do {stuff}
is ok, as \y
is expanded to \x
then to {a}{b}{c}
. One can also have \def\x {{a} {b} {c}}
, \def\y {{d} {e) {f)}
and then \xintFor* #1 in {\x\y} \do {...}
is like \xintFor* #1 in {{a}{b}{c}{d}{e}{f}} \do {...}
.
You have no hope to get such a gigantic table in a normal document: even in landscape mode and \tiny
size the overfull is 500pt, that is about 17cm or 7in.
However, here's a general solution that works for any number of components, here I give an example with four. I add also the definition for \chisum
already discussed. No problem with spaces.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\chisum}{m} % a homage to John Wayne
{
\aentropy_chisum:n { #1 }
}
\seq_new:N \l_aentropy_chisum_seq
\int_new:N \l_aentropy_chisum_index_int
\cs_new_protected:Npn \aentropy_chisum:n #1
{
\seq_clear:N \l_aentropy_chisum_seq
\int_zero:N \l_aentropy_chisum_index_int
\clist_map_inline:nn { #1 }
{
\int_incr:N \l_aentropy_chisum_index_int
\aentropy_add_summand:n { ##1 }
}
\seq_use:Nn \l_aentropy_chisum_seq { \oplus }
}
\cs_new:Npn \aentropy_add_summand:n #1
{
\str_if_eq:nnF { #1 } { 0 }
{
\seq_put_right:Nx \l_aentropy_chisum_seq
{
\str_if_eq:nnF { #1 } { 1 } { #1 }
\exp_not:n { \chi }
\c_math_subscript_token
{ \int_to_arabic:n { \l_aentropy_chisum_index_int } }
}
}
}
\NewDocumentCommand{\clebschtable}{mm}
{
\aentropy_clebschtable:no { #1 } { #2 }
}
\tl_new:N \l_aentropy_clebschtable_tl
\int_new:N \l_aentropy_clebschtable_row_int
\cs_new_protected:Npn \aentropy_clebschtable:nn #1 #2
{
\tl_clear:N \l_aentropy_clebschtable_tl
\int_zero:N \l_aentropy_clebschtable_row_int
\aentropy_make_first_row:n { #1 }
\clist_map_inline:nn { #2 }
{
\int_incr:N \l_aentropy_clebschtable_row_int
\tl_put_right:Nx \l_aentropy_clebschtable_tl
{
\chi
\c_math_subscript_token
{ \int_to_arabic:n { \l_aentropy_clebschtable_row_int } }
}
\clist_map_inline:nn { ##1 }
{
\tl_put_right:Nn \l_aentropy_clebschtable_tl { & \aentropy_chisum:n { ####1 } }
}
\tl_put_right:Nn \l_aentropy_clebschtable_tl { \\ }
}
\begin{array}{l|*{#1}{c}}%| % to keep emacs happy
\l_aentropy_clebschtable_tl
\end{array}
}
\cs_generate_variant:Nn \aentropy_clebschtable:nn { no }
\cs_new_protected:Npn \aentropy_make_first_row:n #1
{
\tl_put_right:Nn \l_aentropy_clebschtable_tl { \bigotimes }
\int_step_inline:nnnn { 1 } { 1 } { #1 }
{
\tl_put_right:Nn \l_aentropy_clebschtable_tl
{
& \chi
\c_math_subscript_token
{ ##1 }
}
}
\tl_put_right:Nn \l_aentropy_clebschtable_tl { \\ \hline }
}
\ExplSyntaxOff
\begin{document}
$\chisum{5,2,7,8,2,0,0,1,3}$
\bigskip
\def\clebschdata {
{
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,2,0,1},
},
{
{0,1,0,0},
{0,0,1,0},
{1,0,0,3},
{0,0,0,1},
},
{
{0,0,1,1},
{1,0,0,0},
{0,1,0,0},
{0,0,3,0},
},
{
{0,0,0,1},
{4,0,0,1},
{0,2,0,0},
{0,0,1,0},
}
}
$\clebschtable{4}{\clebschdata}$
\end{document}
Just for the record, here's the gigantic table all in one PNG
With line breaks; when an optional argument is specified, the macros assume the cells are huge, so they are typeset in \scriptsize
in the stated width; the column and row headers are still in normal size.
\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath,array,pdflscape}
\newcolumntype{C}[1]{>{\centering\scriptsize\arraybackslash$}m{#1}<{$}}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\chisum}{m} % a homage to John Wayne
{
\aentropy_chisum:n { #1 }
}
\seq_new:N \l_aentropy_chisum_seq
\int_new:N \l_aentropy_chisum_index_int
\cs_new_protected:Npn \aentropy_chisum:n #1
{
\seq_clear:N \l_aentropy_chisum_seq
\int_zero:N \l_aentropy_chisum_index_int
\clist_map_inline:nn { #1 }
{
\int_incr:N \l_aentropy_chisum_index_int
\aentropy_add_summand:n { ##1 }
}
\seq_use:Nn \l_aentropy_chisum_seq { \oplus }
}
\cs_new:Npn \aentropy_add_summand:n #1
{
\str_if_eq:nnF { #1 } { 0 }
{
\seq_put_right:Nx \l_aentropy_chisum_seq
{
\str_if_eq:nnF { #1 } { 1 } { #1 }
\exp_not:n { \chi }
\c_math_subscript_token
{ \int_to_arabic:n { \l_aentropy_chisum_index_int } }
}
}
}
\NewDocumentCommand{\clebschtable}{omm}
{
\IfNoValueTF{#1}
{ \aentropy_clebschtable:nno { } { #2 } { #3 } }
{ \aentropy_clebschtable:nno { #1 } { #2 } { #3 } }
}
\tl_new:N \l_aentropy_clebschtable_tl
\int_new:N \l_aentropy_clebschtable_row_int
\cs_new_protected:Npn \aentropy_clebschtable:nnn #1 #2 #3
{
\tl_clear:N \l_aentropy_clebschtable_tl
\int_zero:N \l_aentropy_clebschtable_row_int
\aentropy_make_first_row:n { #2 }
\clist_map_inline:nn { #3 }
{
\int_incr:N \l_aentropy_clebschtable_row_int
\tl_put_right:Nx \l_aentropy_clebschtable_tl
{
\chi
\c_math_subscript_token
{ \int_to_arabic:n { \l_aentropy_clebschtable_row_int } }
}
\clist_map_inline:nn { ##1 }
{
\tl_put_right:Nn \l_aentropy_clebschtable_tl { & \aentropy_chisum:n { ####1 } }
}
\tl_put_right:Nn \l_aentropy_clebschtable_tl { \\ }
}
\tl_if_empty:nTF { #1 }
{ \begin{array}{l|*{#2}{c}} }%| % to keep emacs happy
{ \begin{array}{l|*{#2}{C{#1}}} }%| % to keep emacs happy
\l_aentropy_clebschtable_tl
\end{array}
}
\cs_generate_variant:Nn \aentropy_clebschtable:nnn { nno }
\cs_new_protected:Npn \aentropy_make_first_row:n #1
{
\tl_put_right:Nn \l_aentropy_clebschtable_tl { \bigotimes }
\int_step_inline:nnnn { 1 } { 1 } { #1 }
{
\tl_put_right:Nn \l_aentropy_clebschtable_tl
{
&
\multicolumn{1}{c}
{
\chi
\c_math_subscript_token
{ ##1 }
}
}
}
\tl_put_right:Nn \l_aentropy_clebschtable_tl { \\ \hline }
}
\ExplSyntaxOff
\begin{document}
% $\chisum{5,2,7,8,2,0,0,1,3}$
% \bigskip
\def\clebschdata {
{
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,2,0,1},
},
{
{0,1,0,0},
{0,0,1,0},
{1,0,0,3},
{0,0,0,1},
},
{
{0,0,1,1},
{1,0,0,0},
{0,1,0,0},
{0,0,3,0},
},
{
{0,0,0,1},
{4,0,0,1},
{0,2,0,0},
{0,0,1,0},
}
}
$\clebschtable{4}{\clebschdata}$
\def\clebschdata {{{1,0,0,0,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,0,0,0,0},{0,0,1,0,0,0,0,0,0,0,0},{0,0,0,1,0,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,0,0,0},{0,0,0,0,0,1,0,0,0,0,0},{0,0,0,0,0,0,1,0,0,0,0},{0,0,0,0,0,0,0,1,0,0,0},{0,0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,0,0,0,0,1,0},{0,0,0,0,0,0,0,0,0,0,1}},{{0,1,0,0,0,0,0,0,0,0,0},{0,0,1,0,0,1,0,0,0,0,0},{1,0,0,0,0,0,0,0,0,1,0},{0,0,0,0,1,0,0,0,0,0,1},{0,0,0,0,0,0,1,1,0,0,0},{0,0,1,0,0,0,0,0,1,1,0},{0,0,0,1,0,0,1,0,0,0,1},{0,0,0,1,0,0,0,1,0,0,1},{0,0,0,0,0,1,0,0,1,1,0},{0,1,0,0,0,1,0,0,1,1,0},{0,0,0,0,1,0,1,1,0,0,1}},{{0,0,1,0,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,0,0,1,0},{0,1,0,0,0,1,0,0,0,0,0},{0,0,0,0,0,0,1,1,0,0,0},{0,0,0,1,0,0,0,0,0,0,1},{0,1,0,0,0,0,0,0,1,1,0},{0,0,0,0,1,0,1,0,0,0,1},{0,0,0,0,1,0,0,1,0,0,1},{0,0,0,0,0,1,0,0,1,1,0},{0,0,1,0,0,1,0,0,1,1,0},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,0,2,0,0,3,3,0}}}
\begin{landscape}
\centering
$\clebschtable[1.8cm]{11}{\clebschdata}$
\end{landscape}
\end{document}
Thanks to jfbu for the data
\documentclass[a4paper]{article}
\usepackage{pdflscape,array}
\makeatletter
\def\clebstable#1{%
\begin{tabular}{l*{12}{>{\centering}p{1.5cm}}}%
$\bigotimes$&$\chi_1$&$\chi_2$&$\chi_3$&$\chi_4$&$\chi_5$&$\chi_6$&$\chi_7$&$\chi_8$&$\chi_9$&$\chi_{10}$&$\chi_{11}$ \tabularnewline
\clebA1#1\relax
\end{tabular}}
\def\clebA#1#2#3{%
$\chi_{#1}$\clebB#2\relax
\ifx\relax#3\else\tabularnewline\expandafter\clebA\expandafter{\the\numexpr#1+1\expandafter}\fi}
\def\clebB#1#2{%
&$\gdef\clebD{\gdef\clebD{\oplus}}\clebC1#1,$%
\ifx\relax#2\else\expandafter\clebB\fi}
\def\clebC#1#2,{%
\ifnum#2=\z@\else
\clebD
\ifnum#2=\@ne\else#2\fi
\chi_{#1}%
\fi
\ifnum#1<11 \expandafter\clebC\expandafter{\the\numexpr#1+1\expandafter}\fi}
\begin{document}
\begin{landscape}\tiny
\clebstable {{{2,1,7,2,9,5,6,0,3,0,2},{1,7,1,1,9,5,1,2,5,8,1},{6,6,1,9,4,1,5,7,3,1,9},{1,9,9,1,4,0,6,7,8,6,5},{2,5,5,5,9,5,2,7,3,7,3},{2,5,8,9,0,5,7,7,4,0,0},{5,5,2,9,2,3,9,8,1,7,5},{7,0,3,0,4,1,0,8,1,8,9},{9,6,6,3,6,6,7,2,5,9,5},{0,4,4,8,1,5,0,1,6,9,9},{2,7,2,7,4,6,4,8,2,5,9}},{{3,4,6,0,0,0,1,0,5,6,5},{4,2,6,4,0,3,0,0,0,5,8},{1,0,9,8,4,5,2,1,6,5,0},{3,1,9,6,0,4,1,4,8,6,9},{0,7,6,7,5,7,8,2,2,8,1},{7,7,9,9,2,2,1,6,8,0,2},{5,4,9,7,8,9,5,7,1,9,2},{4,1,4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