r/dailyprogrammer • • Oct 13 '12
[10/13/2012] Challenge #103 [easy-difficult] (Text transformations)
Easy
Back in the 90s (and early 00s) people thought it was a cool idea to \/\/|2][73 |_1|<3 7H15 to bypass text filters on BBSes. They called it Leet (or 1337), and it quickly became popular all over the internet. The habit has died out, but it's still quite interesting to see the various replacements people came up with when transforming characters.
Your job's to write a program that translates normal text into Leet, either by hardcoding a number of translations (e.g. A becomes either 4 or /-\, randomly) or allowing the user to specify a random translation table as an input file, like this:
A 4 /-\
B |3 [3 8
C ( {
(etc.)Each line in the table contains a single character, followed by whitespace, followed by a space-separated list of possible replacements. Characters should have some non-zero chance of not being replaced at all.
Intermediate
Add a --count option to your program that counts the number of possible outcomes your program could output for a given input. Using the entire translation table from Wikipedia, how many possible results are there for ./leet --count "DAILYPROG"? (Note that each character can also remain unchanged.)
Also, write a translation table to convert ASCII characters to hex codes (20 to 7E), i.e. "DAILY" -> "4441494C59".
Difficult
Add a --decode option to your program, that tries to reverse the process, again by picking any possibility randomly: /\/\/ could decode to M/, or NV, or A/V, etc.
Extend the --count option to work with --decode: how many interpretations are there for a given input?
3
u/robin-gvx 0 2 Oct 13 '12 edited Oct 13 '12
Intermediate, without the "Also".
Edit: also:
2
u/IceDane 0 0 Oct 14 '12
Is it just me, or is everyone's count for "dailyprogrammer" off, here?
The number of possibilites would be the product of all the possible transformations for every letter + 1(for unchanged) in "dailyprogrammer", no? According to my code, the possibly transformations for each letter in "dailyprogrammer", accounting for no change, is: [('d',10),('a',10),('i',8),('l',9),('y',11),('p',15),('r',16),('o',7),('g',10),('r',16),('a',10),('m',20),('m',20),('e',6),('r',16)]
The product of this is 8174960640000000.
7
u/skeeto -9 8 Oct 13 '12 edited Oct 13 '12
In Emacs Lisp, easy and intermediate:
Using the Wikipedia table:
And difficult:
Due to ambiguities in the Wikipedia table, it doesn't work too impressively.
2
u/spacemoses 1 1 Oct 13 '12 edited Oct 13 '12
TypeScript (with rendered Javascript) for the easy challenge:
TypeScript:
Rendered JavaScript:
2
u/elemental_1_1 Oct 15 '12
Just easy, using java:
2
u/Die-Nacht 0 0 Oct 15 '12
Python, Easy:
2
u/liaobaishan Oct 16 '12
my first one of these :) Python:
2
u/niHiggim Oct 17 '12 edited Oct 17 '12
Python, with intermediate and difficult. Spits out the whole list of candidate decodings, sorted so that ones with more dictionary words are shown first:
2
u/pivotallever Oct 13 '12 edited Oct 13 '12
Easy is complete. I implemented a default table, a way to read in a user-provided table, changing the amount of characters replaced, and reading the text to translate as an argument or from stdin.
Oh, this requires docopt, which is awesome. argparse and optparse are garbage compared to docopt. The entire command line argument parser is defined in the docstring, and it just works.
python
output:
1
u/[deleted] Oct 14 '12 edited Oct 14 '12
Easy mode in C#
}
I want to extend it to include more than one l337 character for each letter, and also not ignore numbers. After homework is done I suppose :/
1
u/[deleted] Nov 12 '12 edited Nov 12 '12
Python 2.7
uses a table in the following format:
1
u/ben174 Nov 27 '12
NOTE: The Wikipedia article mentioned in the summary has been edited to remove the list that is referenced.
Here's the old revision which contains the list.
1
u/ben174 Nov 27 '12
Python
1
u/marekkpie Jan 22 '13
Lua, just easy:
1
u/dreugeworst Oct 14 '12
Haskell, without the also. Still don't feel very comfortable writing haskell, but I'm relatively happy with the result =)
0
u/[deleted] Oct 14 '12
[deleted] — view deleted comment