s = Table[Random[Integer, {1, 1000}], {11}];
x = Table[0.2  z - 1.2, {z, 11}];
y = Table[0 z, {z, 11}];
g = Table[0, {11}];
m = Table[RGBColor[1, 1, 1], {11}];

  
Part[g, 1] = RGBColor[0, 0, 0];
Part[g, 2] = RGBColor[0, 0, 1];
Part[g, 3] = RGBColor[0, 1, 0];
Part[g, 4] = RGBColor[0, 1, 1];
Part[g, 5] = RGBColor[1, 0, 0];
Part[g, 6] = RGBColor[1, 0, 1];
Part[g, 7] = RGBColor[1, 1, 0];
Part[g, 8] = RGBColor[0.5, 0.5, 0.5];
Part[g, 9] = RGBColor[0, 0.5, 0.5];
Part[g, 10] = RGBColor[0.5, 0, 0.5];
Part[g, 11] = RGBColor[0.5, 0.5, 0];

\( (*数字と玉の位置を定義*) \)
teigi[]:={
moji1={Part[m, 1],Text[
                        Part[s,  1], {Part[x,  1], Part[y,  1]}]};
tama1={Part[g, 1], 
                  Disk[{Part[x,  1], Part[y,  1]}, 0.1]};

moji2={Part[m, 2],
Text[
                        Part[s,  2], {Part[x,  2], Part[y,  2]}]};
tama2={Part[g, 2], 
                  Disk[{Part[x,  2], Part[y,  2]}, 0.1]};

moji3={Part[m, 3],
Text[
                        Part[s,  3], {Part[x,  3], Part[y,  3]}]};
tama3={Part[g, 3], 
                  Disk[{Part[x,  3], Part[y,  3]}, 0.1]};

moji4={Part[m, 4],Text[
                        Part[s,  4], {Part[x,  4], Part[y,  4]}]};
tama4={Part[g, 4], 
                  Disk[{Part[x,  4], Part[y,  4]}, 0.1]};

moji5={Part[m, 5],Text[
                        Part[s,  5], {Part[x,  5], Part[y,  5]}]};
tama5={Part[g, 5], 
                  Disk[{Part[x,  5], Part[y,  5]}, 0.1]};

moji6={Part[m, 6],Text[
                        Part[s,  6], {Part[x,  6], Part[y,  6]}]};
tama6={Part[g, 6], 
                  Disk[{Part[x,  6], Part[y,  6]}, 0.1]};

moji7={Part[m, 7],Text[
                        Part[s,  7], {Part[x,  7], Part[y,  7]}]};
tama7={Part[g, 7], 
                  Disk[{Part[x,  7], Part[y,  7]}, 0.1]};

moji8={Part[m, 8],Text[
                        Part[s,  8], {Part[x,  8], Part[y,  8]}]};
tama8={Part[g, 8], 
                  Disk[{Part[x,  8], Part[y,  8]}, 0.1]};

moji9={Part[m, 9],Text[
                        Part[s,  9], {Part[x,  9], Part[y,  9]}]};
tama9={Part[g, 9], 
                  Disk[{Part[x,  9], Part[y,  9]}, 0.1]};

moji10={Part[m, 10],Text[
                        Part[s,  10], {Part[x,  10], Part[y,  10]}]};
tama10={Part[g, 10], 
                  Disk[{Part[x,  10], Part[y,  10]}, 0.1]};

moji11={Part[m, 11],Text[
                        Part[s,  11], {Part[x,  11], Part[y,  11]}]};
tama11={Part[g, 11], 
                  Disk[{Part[x,  11], Part[y,  11]}, 0.1]};
}

\( (*グラフィックを表示する*) \)
byousya[] := {
Show[
              Graphics[{tama1, tama2, tama3, tama4, tama5, tama6, tama7, 
                  tama8, tama9, tama10, tama11, moji1, moji2, moji3, moji4, 
                  moji5, moji6, moji7, moji8, moji9, moji10, 
                  moji11}, {PlotRange -> {{-1.1, 1.1}, {-1.1, 
                        1.1}}, 
AspectRatio -> 
                    1}
]
]
}

  
swap[a_, b_]:={
  
x1=Part[x,  a];
x2 = Part[x,  b];
s1 = Part[s,  a];
s2 = Part[s,  b];
g1 = Part[g, a];
g2 = Part[g, b];

\( (*要素の置換の可視化*) \)
\( (*置換する要素の座標をtの関数で表す*) \)
tyusin = (Part[x,  a] + 
                      Part[x,  b])/2;
hankei = (Part[x,  a] - Part[x,  b])/2;
Part[x,  a] = hankei Cos[t] + tyusin;
Part[y,  a] = hankei Sin[t];
Part[x,  b] = hankei Cos[t + Pi] + tyusin;
Part[y,  b] = hankei Sin[t + Pi];
\( (*tの関数で表した座標を適用*) \)
teigi[];

\( (*実際にアニメを実行*) \)
Do[
byousya[], 
{t, 0,  Pi, Pi/10}
];

\( (*要素を実際に置換*) \)
\( (*格玉の座標はそのまま*) \)
Part[x,  a] = x1;
Part[x,  b] = x2;
Part[y,  a] = 0;
Part[y,  b] = 0;
  
Part[s,  a] = s2;
Part[s,  b] = s1;
Part[g, a] = g2;
Part[g, b] = g1;
  
teigi[];
}

  
\(For[i = 1, 
            i ≤ 12, \(i++\), 
For[j = 1, 
              j ≤ 12 - i, \(j++\), 
If[
                Part[s, \ j] <= Part[s, \ j - 1], 
                swap[j, 
                  j - 1], , ]
]; 
 (*ソ - ト済みのデ - タを判り易くするため, 玉と数字の色を変える*) 
Part[g, 12 - i] = 
              RGBColor[1, 1, 1]; 
Part[m, 12 - i] = 
              RGBColor[0, 0, 
                0]; 
teigi[]; 
byousya[];
];\)