Javascript(49 + 5635)* 10/2174 = 26.14
オンラインデモ:
「リアルディクショナリ」オプションはドロップボックスでは機能しませんが、実際のWebサーバーで実行すると機能します。Visual Studio開発サーバーとGoogle Chromeでテスト済み。
https://dl.dropboxusercontent.com/u/141246873/leettranslator/index.html
スコア:
49リートアイテム= 49
大文字のボーナス= 5 * 49 = 245
辞書検索ボーナス= 20 * 49 = 980
感嘆ボーナス* 3 = 90 * 49 = 4410
(リートアイテム+ボーナス)* 10 /(コード長)
(49 + 5635)* 10/2174 = 26.14
コード:
function IsInDict(e) { return W[e] } function translate(e) { words = e.split(" "); res = ""; for (var t in words) { ex = ""; function n(e, r, i) { var s = false; for (var o = 1; o <= e.length; o++) { var u = e.substring(0, o) === "!" || i; var a = et[e.substring(0, o)]; var f = e.substring(o); if (a) { s = true; if (f.length === 0) { if (u) { ex = r + a; words[t] = "" } } else n(f, r + a, u) } } if (i && !s && r) { ex = r; words[t] = e.split("").reverse().join("") } } n(words[t].split("").reverse().join(""), "", false); mes = []; function r(e, t) { for (var n = 1; n <= e.length; n++) { var i = tokens[e.substring(0, n)]; var s = e.substring(n); if (i) { mFound = true; if (s.length === 0) for (var o in i) { mes.push(t + i[o]) } else for (var o in i) r(s, t + i[o]) } } if (e.length > 1) r(e.substring(1), t + e.substring(0, 1)); else { mes.push(t + e) } } m = ""; if (words[t] !== "") { r(words[t].toLowerCase(), ""); if (mes.length === 1) m = mes[0]; else { sl = []; for (var i in mes) { if (IsInDict(mes[i].slice(-1) === "." ? mes[i].substring(0, mes[i].length - 1) : mes[i])) { sl.push(mes[i]) } } if (sl.length > 0) m = sl[0]; else m = mes[0] } if (res === "") { m = cap(m) } if (res.slice(-1) === ".") { m = cap(m) } } res += " " + m; if (ex !== "") res += ex } return res.trim() } function cap(e) { return e.charAt(0).toUpperCase() + e.slice(1) } tokens = { $: ["s"], "(": ["c"], 5: ["s"], "@": ["a"], 4: ["a", "for"], 3: ["e"], "+": ["t"], "#": ["h"], teh: ["the"], "'d": ["ed"], pwnd: ["pwned"], pwnt: ["pwned"], k: ["ok"], kk: ["ok"], 0: ["o"], y: ["why"], txt: ["text"], dafuq: ["what the f**k"], "/\\": ["a"], "^": ["a"], "\\/": ["v"], d00d: ["dude"], n00b: ["newbie"], "\\/\\/": ["w"], 8: ["b", "ate"], "|_|": ["u"], "|-|": ["h"], "Я": ["r"], j00: ["you"], joo: ["you"], vv: ["w"], tomoz: ["tomorrow"], "|<": ["k"], "[)": ["d"], "|)": ["d"], "<3": ["love"], "><": ["x"], 10100111001: ["leet"], 2: ["to", "too"], ur: ["your", "you're"], u: ["you"], x: ["ks", "cks"], z: ["s"], 1: ["i", "l"], "!": ["i"], c: ["see", "sea"], b: ["be", "bee"], "&": ["and", "anned", "ant"], 7: ["and", "anned", "ant", "t"] }; et = { eno: "!", nevele: "!!", 1: "!", "!": "!" }
ゴルフをしていない:
tokens={
'$':['s'],'(':['c'],'5':['s'],'@':['a'],'4':['a','for'],'3':['e'],'+':['t'],'#':['h'],'teh':['the'],"'d":['ed'],'pwnd':['pwned'],
'pwnt':['pwned'],'k':['ok'],'kk':['ok'],'0':['o'],'y':['why'],'txt':['text'],'dafuq':['what the f**k'],
'/\\':['a'],'^':['a'],'\\/':['v'],'d00d':['dude'],'n00b':['newbie'],
'\\/\\/':['w'],'8':['b','ate'],'|_|':['u'],'|-|':['h'],'Я':['r'],'j00':['you'],
'joo':['you'],'vv':['w'],'tomoz':['tomorrow'],'|<':['k'],'[)':['d'],'|)':['d'],'<3':['love'],
'><':['x'],'10100111001':['leet'],'2':['to','too'],'ur':["your","you're"],
'u':['you'],'x':['ks','cks'],'z':['s'],'1':['i','l'],'!':['i'],'c':['see','sea'],
'b':['be','bee'],'&':['and','anned','ant'],'7':['and','anned','ant','t']}
var excTokens = {'eno':'!','nevele':'!!','1':'!','!':'!'}
function IsInDict(word)
{
return (W[word]);
}
function translate(input) {
var words = input.split(" ");
var result = "";
for (var i in words) {
var exclamations = "";
function parseExclamations(s, prev, exclamationFound) {
var matchFound = false;
for (var j = 1; j <= s.length; j++) {
var hasExclamation = (s.substring(0, j) === "!") || exclamationFound;
var currentToken = excTokens[s.substring(0, j)];
var remaining = s.substring(j);
if (currentToken) {
matchFound = true;
if (remaining.length === 0) {
if (hasExclamation) {
exclamations = prev + currentToken;
words[i] = "";//word only had exclamations in it so dont parse the rest of it
}
}
else
parseExclamations(remaining, prev + currentToken, hasExclamation);
}
}
if (exclamationFound && !matchFound && prev) {
exclamations = prev;
words[i] = s.split("").reverse().join("");//reverse back again
}
}
var reverseWord = words[i].split("").reverse().join("");
parseExclamations(reverseWord, "", false);
var matches = []
function parse(s, prev) {
for (var j = 1; j <= s.length; j++) {
var currentTokenArray = tokens[s.substring(0, j)];
var remaining = s.substring(j);
if (currentTokenArray) {
matchFound = true;
if (remaining.length === 0)
for (var k in currentTokenArray) {
matches.push(prev + currentTokenArray[k]);
}
else
for (var k in currentTokenArray)
parse(remaining, prev + currentTokenArray[k]);
}
}
if (s.length > 1)
parse(s.substring(1), prev + s.substring(0, 1));
else {
matches.push(prev + s);
}
}
var match = "";
if (words[i] !== "") {
parse(words[i].toLowerCase(), "");
//check the dictionary
if (matches.length === 1)
match = matches[0];
else {
var shortlist = [];
for (var j in matches) {
//check dictionary. allow for a full stop at the end of the word
var isInDict = IsInDict(matches[j].slice(-1) === "." ? matches[j].substring(0, matches[j].length - 1) : matches[j]);
if (isInDict) {
shortlist.push(matches[j]);
}
}
if (shortlist.length > 0)
match = shortlist[0];
else
match = matches[0];
}
if (result === "") {
match = cap(match);
}
if (result.slice(-1) === ".") {
match = cap(match);
}
}
result += " " + match;
if (exclamations !== "")
result += exclamations;
}
return result.trim();
}
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
試験結果:
- |-| 3 15 $ | _ |(#@ n00b ====>彼はそんな初心者です
- @ 1 // 4Y5 p0 $ + ur n3VV qu35710nz 1n teh $&80x ====>新しい質問は常にサンドボックスに投稿してください
- !!! 1 !! 1 ====> !!!!!!!
- !!!1!====> !!!!!
- !eleven ====> !!!
- teh !!! 1 !! 1 ====> The !!!!!!!
- !!!!!! ====> !!!!!
- teh!eleven ====> The !!!
- !!! 1 !! 1 ====> !!!!!!!
- qu35710nz!1!====>質問!!!
- +357 +357。735+ ====>テストテスト。テスト
- &31!73#4(KER $ WR0 + 3 83773R L!K3 +#!5 7#@ N 2D @ Y ====>そして、エリートハッカーは今日よりもこのように書いた
ノート:
辞書は、すべての単語を含むWと呼ばれるオブジェクトを備えた別個のJavaScriptファイルです。これには、関連するテストを実行するために必要な単語が含まれています。