https://www.codewars.com/kata/strings-mix/csharp
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
public class Mixing
{
public static string Mix(string s1, string s2)
{
string mix = "";
List<KeyValuePair<string, string>> mixlist = new List<KeyValuePair<string, string>>();
s1 = Regex.Replace(s1, "[^a-z]", "");
s2 = Regex.Replace(s2, "[^a-z]", "");
string disStr1 = string.Join("", (from s in s1 where s1.Count(o => o == s) > 1 select s).Distinct().ToArray());
string disStr2 = string.Join("", (from s in s2 where s2.Count(o => o == s) > 1 select s).Distinct().ToArray());
for (int i = 0; i < disStr1.Length; i++)
{
int scount1 = s1.Count(o => o == disStr1[i]);
int scount2 = s2.Count(o => o == disStr1[i]);
string key = scount1 > scount2 ? "1" : scount1 < scount2 ? "2" : "3";
string value = "";
if (key == "1")
{
for (int j = 0; j < scount1; j++)
{
value += disStr1[i];
}
}
else
{
for (int k = 0; k < scount2; k++)
{
value += disStr1[i];
}
}
KeyValuePair<string,string> item = new KeyValuePair<string,string>(key,value);
mixlist.Add(item);
disStr2 = disStr2.Replace(disStr1[i].ToString(), "");
}
for (int i = 0; i < disStr2.Length; i++)
{
int scount2 = s2.Count(o => o == disStr2[i]);
string key = "2";
string value = "";
for (int j = 0; j < scount2; j++)
{
value += disStr2[i];
}
KeyValuePair<string, string> item = new KeyValuePair<string, string>(key, value);
mixlist.Add(item);
}
var mixArr = (from l in mixlist orderby l.Value.Length descending,l.Key,l.Value select l).ToArray();
for (int i = 0; i < mixArr.Length; i++)
{
mix += mixArr[i].Key + ":" + mixArr[i].Value + "/";
}
if(mix.Length > 0)
{
mix = mix.Substring(0,mix.Length-1);
mix = mix.Replace("3","=");
}
return mix;
}
}