-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToLeetSpeak.cs
94 lines (80 loc) · 2.62 KB
/
ToLeetSpeak.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Linq;
namespace CodingChallenges;
[TestClass]
public class ToLeetSpeakClass {
[TestMethod]
public void Test() {
/*
ToLeetSpeak
Your task is to write a function toLeetSpeak that converts a regular english sentence to Leetspeak.
More about LeetSpeak You can read at wiki -> https://en.wikipedia.org/wiki/Leet
Consider only uppercase letters (no lowercase letters, no numbers) and spaces.
For example:
toLeetSpeak("LEET") returns "1337"
In this kata we use a simple LeetSpeak dialect. Use this alphabet:
{
A : '@',
B : '8',
C : '(',
D : 'D',
E : '3',
F : 'F',
G : '6',
H : '#',
I : '!',
J : 'J',
K : 'K',
L : '1',
M : 'M',
N : 'N',
O : '0',
P : 'P',
Q : 'Q',
R : 'R',
S : '$',
T : '7',
U : 'U',
V : 'V',
W : 'W',
X : 'X',
Y : 'Y',
Z : '2'
}
*/
Assert.AreEqual("1337", ToLeetSpeak("LEET"));
Assert.AreEqual("(0D3W@R$", ToLeetSpeak("CODEWARS"));
Assert.AreEqual("#3110 W0R1D", ToLeetSpeak("HELLO WORLD"));
Assert.AreEqual("10R3M !P$UM D010R $!7 @M37", ToLeetSpeak("LOREM IPSUM DOLOR SIT AMET"));
Assert.AreEqual("7#3 QU!(K 8R0WN F0X JUMP$ 0V3R 7#3 1@2Y D06", ToLeetSpeak("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"));
}
public static string ToLeetSpeak(string str) {
var codepage = @" A : @,
B : 8,
C : (,
D : D,
E : 3,
F : F,
G : 6,
H : #,
I : !,
J : J,
K : K,
L : 1,
M : M,
N : N,
O : 0,
P : P,
Q : Q,
R : R,
S : $,
T : 7,
U : U,
V : V,
W : W,
X : X,
Y : Y,
Z : 2"
.Split(",").Select(x => x.Split(":")).ToDictionary(x => x.First().Trim().First(), x => x.Last().Trim().First());
return string.Concat(str.Select(c => codepage.TryGetValue(c, out var val) ? val : c));
}
}