25
\$\begingroup\$

Your challenge is to write a program to translate (English) leetspeak/lolspeak/txtspk into normal English. Your program should read from standard input and output to standard output, unless your language does not support these.

You may use a file containing a list of words in the English language, separated by new lines. It should be called W and will be located in the same directory as your program. (On GNU/Linux systems and possibly others, you can make W a link to /usr/share/dict/words) The list doesn't have to be all-lowercase, you can use it to determine whether words should have capitals.

This is based on a now-deleted question posted by Nikos M. which could be found here. This is not a duplicate as this original question was closed and did not receive any answers, because there was no winning criterion and the user was unwilling to put one in.

Scoring

The scoring is a bit complicated!

Your score is

(leet items + bonuses) * 10 / (code length)

Highest score wins.

Your program doesn't have to be and probably can't be perfect, but the more accurate it is, the more bonuses it gets!

Since $ can mean both s and S, you get a bonus of 5 points per leet item for deciding whether it should have a capital letter (i.e. capital letters at the start of sentences).

You get a further bonus of 5 points per leet item for implementing proper nouns (words which always have capitals) - the way this works is that you would look through the word list, make the output capitalised if only a capitalised version is present in the list, and if both versions are there, just guess.

If a character has two meanings (e.g. 1 can mean L or I), you get 20 points per leet item for only picking those translations of the item which make real English words - use the wordlist for this. If more than one translation of a leet item makes a real English word, you can arbitrarily pick one of the valid translations and still get the bonus.

List of Leet

These are the leet items which you may implement. You don't have to implement all of them, but the more you add, the more points you get.

You cannot ever score points by translating an item or character to itself. This rule overrides any mistakes I might have made in the list.

It's tempting to do a simple tr or s/.../.../g. The real challenge is to determine which of multiple meanings could and couldn't be correct, using the wordlist.

Leet Items (each of these adds 1 to leet items in the formula)

$      -> s,S
(      -> c,C
5      -> s,S
@      -> a,A
4      -> a,A
3      -> e,E
7      -> t,T
+      -> t,T
#      -> h,H
teh    -> the
'd     -> ed
pwnd   -> pwned
pwnt   -> pwned
k,K    -> OK
kk     -> OK
0[zero]-> o,O
y,Y    -> why
4      -> for
txt    -> text
dafuq  -> what the f**k
/\,^   -> a,A
\/     -> v,V
d00d   -> dude
n00b   -> newbie
\/\/   -> w,W
8      -> b,B
|_|    -> u,U
|-|    -> h,H
Я      -> r,R
j00    -> you
joo    -> you
vv,VV  -> w,W
tomoz  -> tomorrow
|<     -> k,K
[),|)  -> d,D
<3     -> love
><     -> x,X
10100111001       -> leet (binary representation of 1337)
2      -> to,too
ur,UR  -> your,you're (no need to correctly distinguish between the two)
u,U    -> you
8      -> -ate-,8
x,X    -> -ks-,-cks-
z,Z    -> s,S
1      -> i,I,l,L
!      -> i,I,!
c,C    -> see,C,sea
b,B    -> be,B,bee
[accented letter] -> [non-accented form] (score 1 per accented letter supported)
&,7    -> and,anned,ant (may be used in the middle of a word)

Harder "Leet": score 30 points for leet items each

!!!1!!1-> !!!!!!! (translate 1's in a sequence of !'s into !'s)
!!!one!-> !!!!!
!eleven-> !!!

Examples

These are examples of what a program which implements all the leet characters above, and some of the bonuses, might be able to do:

Example sentence: |-|3 15 $|_|(# @ n00b = He is such a newbie

Leet-based censorship: $#!+ = s**t

Extreme leet: \/\/ 1 |< 1 P 3 [) 1 A = Wikipedia

-xor suffix: H4X0R = hacker

More extreme leet: @1\/\/4Y5 p0$+ ur n3VV qu35710nz 1n teh $&80x = Always post your new questions in the sandbox

Example Scoring

Bash, 10 characters, 3 items, no bonuses:

tr 137 let

This scores ( 1 * 3 ) * 10 / 10 = 3.

\$\endgroup\$
12
  • \$\begingroup\$ Sorry I didn't catch this in the sandbox, but if you're multiplying the bonuses by 10 they are still worth a lot more than the words themselves. Is that your intention? \$\endgroup\$ May 30, 2014 at 9:26
  • \$\begingroup\$ @m.buettner It's to combat simply using tr or s/.../.../g. Just translating things like that would make a boring challenge, so we need to reward better translations which use the wordlist \$\endgroup\$
    – user16402
    May 30, 2014 at 9:28
  • \$\begingroup\$ Would a long series of regexps be permissible? I would love to see if it were possible (albeit hard) to do this even in a context-aware way in mostly regexps. (Or maybe a sed script.) \$\endgroup\$
    – Claudia
    May 30, 2014 at 18:19
  • \$\begingroup\$ When I say a sed script, I mean more than a simple s/.../.../g, but a file that is parsed and executed by sed itself. As terse as the language is, it might be a decent golfable language... \$\endgroup\$
    – Claudia
    May 30, 2014 at 18:20
  • \$\begingroup\$ @impinball Regexes are absolutely fine, although I have no idea how you would open the wordlist and parse it with a regex language alone. sed scripts are also fine and could be very interesting, they could do very well on this due to the short substitution syntax, you might be able to read from the wordlist, either with GNU extensions or by using sed as part of a larger Bash program \$\endgroup\$
    – user16402
    May 30, 2014 at 18:25

5 Answers 5

12
+200
\$\begingroup\$

Javascript (49 + 5635) * 10 / 2174 = 26.14

Online Demo:

"Real dictionary" option doesnt work on drop box but it will work if run in a real web server. Tested in visual studio development server and google chrome.

https://dl.dropboxusercontent.com/u/141246873/leettranslator/index.html

Score:

49 leet items = 49

Capitalization bonus = 5 * 49 = 245

dictionary lookup bonus = 20 * 49 = 980

exclamation bonus * 3 = 90 * 49 = 4410

(leet items + bonuses) * 10 / (code length)

(49 + 5635) * 10 / 2174 = 26.14

Code:

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: "!", "!": "!" }

Ungolfed:

            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);
            }

Test results:

  • |-|3 15 $|_|(# @ n00b ====> He is such a newbie
  • @1//4Y5 p0$+ ur n3VV qu35710nz 1n teh $&80x ====> Always post your new questions in the sandbox
  • !!!1!!1 ====> !!!!!!!
  • !!!one! ====> !!!!!
  • !eleven ====> !!!
  • teh!!!1!!1 ====> The!!!!!!!
  • teh!!!one! ====> The!!!!!
  • teh!eleven ====> The!!!
  • teh !!!1!!1 ====> The !!!!!!!
  • qu35710nz!1! ====> Questions!!!
  • +357 +357. 735+ ====> Test test. Test
  • & 31!73 #4(KER$ WR0+3 83773R L!K3 +#!5 7#@N 2D@Y ====> And elite hackers wrote better like this than today

Notes:

The dictionary is a seperate javascript file with an object called W containing all of the words. This just contains the words I needed for running the relevant tests.

\$\endgroup\$
3
  • \$\begingroup\$ If you run that through the Closure Compiler it's only 1640 characters bringing your score to 34. \$\endgroup\$
    – A.M.K
    Jun 8, 2014 at 1:43
  • \$\begingroup\$ what does this file do? dl.dropboxusercontent.com/u/141246873/leettranslator/… is it just to get a dictionary from the web? (i.e. can the program run using W.js if it is removed) \$\endgroup\$
    – user16402
    Jun 8, 2014 at 6:43
  • \$\begingroup\$ @professorfish thats an external js lib with a dictionary in it (words up to ten letters). Its only used if the 'real dictionary' option is selected on the demo. Its just for a demo with a better dictionary and not part of my official answer. \$\endgroup\$
    – rdans
    Jun 8, 2014 at 7:50
7
\$\begingroup\$

Haskell - Score 1.421421421 : (37 items + (21 bonuses (capitalization) * 5)) * 10 / (999 bytes)

This is my final answer.

import System.Environment
import Text.Parsec
import Text.Parsec.String
s=string
r=return
t=try
o=oneOf
(>|)=(<|>)
a p l u=b[p]l u
b (p:q) l u=e(foldl(>|)(s p)$map(s)q)l u
c p l u=e(o p)l u
d p q=t$s p>>r q
e p l u=t$do{p;r l}>|do{s". ";p;r$". "++u}
f p q=t$do{between(t$s" ")(t$s" ")(o p);r q}
g::Parser String
g=do{s<-many$c"$5""s""S">|c"@4^""a""A">|c"3""e""E">|c"7+""t""T">|c"#""h""H">|d"teh""the">|d"'d""ed">|d"pwnd""pwned">|d"pwnt""pwned">|c"kK""ok""OK">|d"kk""OK">|d"n00b""newbie">|f"yY""why">|d"4""for">|d"txt""text">|d"dafuq""what the f**k">|b["\\/\\/","vv","VV"]"w""W">|a"/\\""a""A">|d"d00d""dude">|c"0""o""O">|a"\\/""v""V">|c"8""b""B">|a"|_|""u""U">|a"|-|""h""H">|c"Я""r""R">|b["j00","joo"]"you""you">|d"tomoz""tomorrow">|a"|<""k""K">|b["[)","|)"]"d""D">|d"<3""love">|a"><""x""X">|c"1!""i""I">|d"10100111001""leet">|c"2""too""to">|d"ur""your">|d"UR""you're">|f"uU""you">|c"xX""ks""cks">|d"&""and">|do{c<-anyChar;return [c]};return$concat s}
main=getArgs>>=putStrLn.show.(parse g"").concat

Tests

When the program is compiled to a file named min-lt, you can write the following shell script

#!/bin/bash
./min-lt "|-|3 15 $|_|(# @ n00b"
./min-lt "\$#!+"
./min-lt "\/\/ 1 |< 1 P 3 [) 1 A"
./min-lt "H4X0R"
./min-lt "@1\/\/4Y5 p0$+ ur n3VV qu35710nz 1n teh $&80x"
./min-lt "+357 +357. 735+"

which will print this

Right "he is su(h a newbie"
Right "shit"
Right "w i k i P e d i A"
Right "HaksoR"
Right "aiwaYs post your new questionz in the sandboks"
Right "test test. Test"
\$\endgroup\$
8
  • \$\begingroup\$ by -ks- I meant ks in the middle of a word. I'll have a look at this as soon as I find a haskell compiler \$\endgroup\$
    – user16402
    May 31, 2014 at 9:45
  • \$\begingroup\$ Just install the haskell-platform package. Do you have an example for ks? \$\endgroup\$
    – gxtaillon
    May 31, 2014 at 17:45
  • \$\begingroup\$ <insertnamehere> rocX or roX \$\endgroup\$
    – user16402
    Jun 1, 2014 at 18:19
  • \$\begingroup\$ I've tested it, it's working \$\endgroup\$
    – user16402
    Jun 1, 2014 at 18:24
  • 1
    \$\begingroup\$ Updated my answer with a score and better handling of word translation. \$\endgroup\$
    – gxtaillon
    Jun 3, 2014 at 8:07
7
\$\begingroup\$

Extended BrainFuck : 0.6757

{a[-])&d}{c(-(-}{d)$t(-}:r:i:t$t,(-$i+$r+)$i($t 6+(-$i 5--)+$i 3+(--&c-(--
(3-(5-&c&c&c-&c--5-((-&d)$r.&d|"A"&a|"B"&a|"T"&a|"S"&a|"A"&a|"E"&a|"TO"&a
|"L"&a|"O"&a|"T"&a|"C"&a|"AND"&a|"S"&a|"H"&a|"I"(-))$i(-)$r(-)$t,(-$i+$r+))

So this does 15 translations "$(5@437+#0821!&" , no bonuses and it has 222 bytes (uneccesary linefeeds not included). 15*10/222 = 0.6757

Usage:

%> beef ebf.bf < leet.ebf > leet.bf
%> echo '& 31337 #4(KER$ WR0+3 83773R L!K3 +#!5 7#@N 2D@Y' | beef  leet.bf
AND ELEET HACKERS WROTE BETTER LIKE THIS THAN TODAY
%>

EBF isn't really made for golfing but it's rle feature, macros and print string feature makes it somewhat easier to compress than BrainFuck. The end compiled BrainFuck binary looks like this:

>>,[-<+<+>>]<[>++++++[-<------>]+<+++[--[-[--[--[---[-----[-[-[-[-[-[--[-[--------[[-]
>[-]<<.>]>[->++++++++[-<++++++++>]<+.[-]]<]>[->++++++++[-<++++++++>]<++.[-]]<]>[->++++
+++++[-<+++++++++>]<+++.[-]]<]>[->+++++++++[-<+++++++++>]<++.[-]]<]>[->++++++++[-<++++
++++>]<+.[-]]<]>[->++++++++[-<+++++++++>]<---.[-]]<]>[->+++++++++[-<+++++++++>]<+++.--
---.[-]]<]>[->++++++++[-<+++++++++>]<++++.[-]]<]>[->+++++++++[-<+++++++++>]<--.[-]]<]>
[->+++++++++[-<+++++++++>]<+++.[-]]<]>[->++++++++[-<++++++++>]<+++.[-]]<]>[->++++++++[
-<++++++++>]<+.+++++++++++++.----------.[-]]<]>[->+++++++++[-<+++++++++>]<++.[-]]<]>[-
>++++++++[-<+++++++++>]<.[-]]<]>[->++++++++[-<+++++++++>]<+.[-]]<[-]<[-]>>,[-<+<+>>]<]
\$\endgroup\$
2
  • 1
    \$\begingroup\$ The compiled BF code seems to work fine, it looks pretty short for a BF program \$\endgroup\$
    – user16402
    Jun 5, 2014 at 14:08
  • \$\begingroup\$ @professorfish Using ~"OTLHEAND" I could made all chars once for 107 bytes object code instead of making them from 0 each time using 354, but my answer is optimized for EBF code size :) \$\endgroup\$
    – Sylwester
    Jun 5, 2014 at 14:40
3
\$\begingroup\$

Java : 1.236

import java.util.*;public class L{static H<String,String>c;static H<String,String>w;static{c=new H();c.p("1","i");c.p("!","i");c.p("$","s");c.p("5","s");c.p("@","a");c.p("4","a");c.p("3","e");c.p("7","t");c.p("+","t");c.p("#","h");c.p("'d","ed");c.p("0","o");c.p("zero","o");c.p("\\/\\/","w");c.p("/\\","a");c.p("\\/","v");c.p("|<","k");c.p("[)","d");c.p("8","b");c.p("|_|","u");c.p("|-|","h");c.p("Я","r");c.p("(","c");c.p("VV","w");c.p("&","and");c.p("2","to");w=new H();w.p("@","a");w.p("teh","the");w.p("pwnd","pwned");w.p("pwnt","pwned");w.p("k","ok");w.p("kk","ok");w.p("y","why");w.p("Y","why");w.p("4","for");w.p("txt","text");w.p("dafuq","what the f**k");w.p("d00d","dude");w.p("n00b","newbie");w.p("j00","you");w.p("joo","you");}public static void main(String[]a){System.out.println(new L().C(a));}String C(String[]o){String x=T(o);for(String d:o){if(w.containsKey(d))x=x.replace(d,w.get(d));else{String r=d;for(String y:c.keySet()){if(d.contains(y))r=r.replace(y,c.get(y));}x=x.replace(d,r);}}return x;}String T(String[]l){String s="";for(String w:l)s+=" "+w;return s;}}class H<T1,T2>extends LinkedHashMap<T1,T2>{T2 p(T1 k,T2 v){return super.put(k,v);}}

So it does the following transformations

+357 +357. 735+
test test. test
|-|3 15 $|_|(# @ n00b
he is such a newbie
$#!+
shit
\/\/ 1 |< 1 P 3 [) 1 A
w i k i P e d i A
@1\/\/4Y5 p0$+ ur n3VV qu35710nz 1n teh $&80x
aiwaYs post ur new questionz in the sandbox
& 31337 #4(KER$ WR0+3 83773R L!K3 +#!5 7#@N 2D@Y
and eieet hacKERs WRote betteR LiKe this thaN toDaY

The score calculation is tricky

  • (leet items + bonuses) * 10 / (code length)
  • code length = 1165 leet
  • leet items = 39 (unique)
  • bonus = 21 (do not know how to calculate so copied MomemtumMori) (Please advise)

((39 + (21*5)) * 10) / 1165 = 1.236

Un-Golfed code :

import java.util.*;

public class L {
    static H<String, String> c;
    static H<String, String> w;

    static {
        c = new H();
        c.p("1", "i");
        c.p("!", "i");
        c.p("$", "s");
        c.p("5", "s");
        c.p("@", "a");
        c.p("4", "a");
        c.p("3", "e");
        c.p("7", "t");
        c.p("+", "t");
        c.p("#", "h");
        c.p("'d", "ed");
        c.p("0", "o");
        c.p("zero", "o");
        c.p("\\/\\/", "w");
        c.p("/\\", "a");
        c.p("\\/", "v");
        c.p("|<", "k");
        c.p("[)", "d");
        c.p("8", "b");
        c.p("|_|", "u");
        c.p("|-|", "h");
        c.p("Я", "r");
        c.p("(", "c");
        c.p("VV", "w");
        c.p("&", "and");
        c.p("2", "to");
        w = new H();
        w.p("@", "a");
        w.p("teh", "the");
        w.p("pwnd", "pwned");
        w.p("pwnt", "pwned");
        w.p("k", "ok");
        w.p("kk", "ok");
        w.p("y", "why");
        w.p("Y", "why");
        w.p("4", "for");
        w.p("txt", "text");
        w.p("dafuq", "what the f**k");
        w.p("d00d", "dude");
        w.p("n00b", "newbie");
        w.p("j00", "you");
        w.p("joo", "you");
    }

    public static void main(String[] a) {
        System.out.println(new L().C(a));
    }

    String C(String[] o) {
        String x = T(o);
        for (String d : o) {
            if (w.containsKey(d)) x = x.replace(d, w.get(d));
            else {
                String r = d;
                for (String y : c.keySet()) {
                    if (d.contains(y)) r = r.replace(y, c.get(y));
                }
                x = x.replace(d, r);
            }
        }
        return x;
    }

    String T(String[] l) {
        String s = "";
        for (String w : l) s += " " + w;
        return s;
    }
}

class H<T1, T2> extends LinkedHashMap<T1, T2> {
    T2 p(T1 k, T2 v) {
        return super.put(k, v);
    }
}
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Would you mind ungolfing it? :D \$\endgroup\$
    – Knerd
    Jun 5, 2014 at 16:44
1
\$\begingroup\$

C# score 45*10/2556=0.176

Program can output almost all lower and upper case letters. Since I'm not using a english word list the first key found in the Dictionary is used. E.g \/\/ becomes vav. If char is first letter of a word ToUpper is applied.

using System;
using System.Collections.Generic;
class L
{
Dictionary<string, string> D;        
public L() 
{ 
D = new Dictionary<string, string>();
M();
}
public void M()
{
D.Add("$", "s,S");
D.Add("(", "c,C");
D.Add("5", "s,S");
D.Add("@", "a,A");
D.Add("4", "a,A,for");
D.Add("3", "e,E");
D.Add("7", "t,T,and,anned,ant");
D.Add("+", "t,T");
D.Add("#", "h,H");
D.Add("teh", "the");
D.Add("'d", "ed");
D.Add("pwnd", "pwned");
D.Add("pwnt", "pwned");
D.Add("k", "OK");
D.Add("K", "OK");
D.Add("kk", "OK");
D.Add("0", "o,O");
D.Add("y", "why");
D.Add("Y", "why");
D.Add("txt", "text");
D.Add("dafuq", "what the f**k");
D.Add("\\/\\/", "w,W");
D.Add("/\\", "a,A");
D.Add("^", "a,A");
D.Add("\\/", "v,V");
D.Add("d00d", "dude");
D.Add("n00b", "newbie");       
D.Add("8", "b,B,ate,8");
D.Add("|_|", "u,U");
D.Add("|-|", "h,H");
D.Add("j00", "you");
//Я      -> r,R
D.Add("joo", "you");
D.Add("vv", "w,W");
D.Add("VV", "w,W");
D.Add("tomoz", "tomorrow");
D.Add("|<", "k,K");
D.Add("[)", "d,D");
D.Add("|)", "d,D");
D.Add("<3", "love");
D.Add("><", "x,X");
D.Add("2", "to,too");
//10100111001       -> leet (binary representation of 1337)
D.Add("ur", "your,you're");
D.Add("UR", "your,you're");
D.Add("u", "you");
D.Add("U", "you");
D.Add("x", "ks,cks");
D.Add("X", "ks,cks");
D.Add("z", "s,S");
D.Add("Z", "s,S");
D.Add("1", "i,I,l,L");
D.Add("!", "i,I,!");
D.Add("c", "see,C,sea");
D.Add("C", "see,C,sea");
D.Add("b", "be,B,bee");
D.Add("B", "be,B,bee");
//[accented letter] -> [non-accented form] (score 1 per accented letter supported)
D.Add("&", "and,anned,ant");
}

int P(string K, out List<string> V)
{
V = new List<string>();
string v,comma=",";
if(D.TryGetValue(K,out v))
{
string[] vv = v.Split(comma.ToCharArray());
foreach(string s in vv)
{
V.Add(s);
}
}
return V.Count;
}

public string E(string X)
{
string e ="";
string S = " ",t,k="";
string[] W = X.Split(S.ToCharArray());
int n = 0,x=0,m=0;
List<string> V=new List<string>();
bool F = false;
foreach(string s in W)
{
n = s.Length;
F = false;
for (int i = 0; i < n; i++)
{
m = 0;
for (int j = 1; j < n - i+1; j++)
{
k = s.Substring(i, j);
x = P(k, out V);
if (x > 0)
{
t = V[0];
if (t.Length == 1 && i == 0)
t = t.ToUpper();
e += t;
m = t.Length;
F = true;
break;
}
}
if (m > 0) i += (m - 1);
}
e += S;
}
return e;
}
static void Main(string[] a)
{
string t = Console.ReadLine();
L x = new L();
t = x.E(t);
Console.WriteLine(t);
Console.ReadLine();
}
}

Here's my test output:

$ -> S 
( -> C 
5 -> S 
@ -> A 
4 -> A 
3 -> E 
7 -> T 
+ -> T 
# -> H 
teh -> the 
'd -> ed 
pwnd -> pwned 
pwnt -> pwned 
k -> OK 
K -> OK 
0 -> O 
y -> why 
Y -> why 
4 -> A 
txt -> text 
dafuq -> what the f**k 
/\ -> A 
^ -> A 
\/ -> V 
d00d -> dude 
n00b -> newbie 
\/\/ -> Vav 
8 -> B 
|_| -> U 
|-| -> H 
j00 -> you 
joo -> you 
vv -> W 
VV -> W 
tomoz -> tomorrow 
|< -> K 
[) -> D 
|) -> D 
<3 -> love 
>< -> X 
2 -> to 
ur -> you 
UR -> you 
u -> you 
U -> you 
8 -> B 
x -> ks 
X -> ks 
z -> S 
Z -> S 
1 -> I 
! -> I 
c -> see 
C -> see 
b -> be 
B -> be 
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.