Straddling checkerboard: Difference between revisions

m
→‎{{header|C#}}: use IReadOnlyDictionary
(→‎{{header|C#}}: added C#)
m (→‎{{header|C#}}: use IReadOnlyDictionary)
Line 503:
class Program
{
public readonly static DictionaryIReadOnlyDictionary<char, string> Val2Keyval2Key;
public readonly static DictionaryIReadOnlyDictionary<string, char> Key2Valkey2Val;
 
static Program()
{
Val2Keyval2Key = new Dictionary<char, string> {
{'A',"30"}, {'B',"31"}, {'C',"32"}, {'D',"33"}, {'E',"5"}, {'F',"34"}, {'G',"35"},
{'H',"0"}, {'I',"36"}, {'J',"37"}, {'K',"38"}, {'L',"2"}, {'M',"4"}, {'.',"78"},
Line 516:
{'9',"799"}, {'Y',"76"}, {'Z',"77"}};
 
Key2Valkey2Val = Val2Keyval2Key.ToDictionary(kv => kv.Value, kv => kv.Key);
}
 
Line 522:
{
return string.Concat(s.ToUpper().ToCharArray()
.Where(c => Val2Keyval2Key.ContainsKey(c)).Select(c => Val2Keyval2Key[c]));
}
 
Line 528:
{
return string.Concat(Regex.Matches(s, "79.|7.|3.|.").Cast<Match>()
.Where(m => Key2Valkey2Val.ContainsKey(m.Value)).Select(m => Key2Valkey2Val[m.Value]));
}
 
Anonymous user