#Python 2.7, 390 342 341 339339 335 bytes:
from re import*
def F(i):
W=X="";S=split;D='[^\w\s*]';Q=lambdaW=X="";S,s=split,sub;D='[^\w\s*]';Q=lambda c,t:len(subs(D,X,c.group()).split()[t])
for m in S(D+'\n''\W\n',subs(D+"*\w*\*\w+\*.*?(?=\s) \w+",lambda v:"a"*([20,10][Q(v,0)%2]+Q(v,1)),subs("'",X,subs("--"," ",i)))):
for g in S(D+''\W ',m):
for q in S('\W',g):
W+=chr(64+len(q))
W+=" "
W=W[:-1]+". "
print subs("@",X,W)
Takes input in the format:
F('''Multi or Single-lined String''')
Can be golfed down a lot more, which I will do whenever I get the chance.
Repl.it with All Test Cases!Repl.it with All Test Cases!
##Explanation:
Uses the immense power of Python's regular expression built-ins to decipher the input. This is the fundamental process the function goes through for each input:
- Firstly, all
--
are replaced with a single space, and every apostrophe is removed. Then, all words containing italicized components and the word proceeding it are both matched in one string and replaced with10 + len(second word)
number of consecutivea
s if the length of the first word isodd
, and20 + len(second word)
consecutivea
s otherwise. This makes use of the following regular expression:
[^\w\s*]*\w*\*\w+\*.*?(?=\s) \w+
For example, if we have the sentence Perpendicular l*ou*nging calms.
, l*ou*nging calms
will be replaced with aaaaaaaaaaaaaaaaaaaaaaaaa
, or 25 a
s, since l*ou*nging
has an even number of characters and calms
has 5. 20+5=25
.
Now, the newly modified input is split at each punctuation mark followed by a newline (
\n
) to get the paragraphs, then each paragraph is split at each punctuation followed by 2 spaces to get the sentences, and finally, each sentence is split into words along any punctuation including a space. Then, for each word (including the runs of consecutivea
s), we add on to a stringW
the letter corresponding to the unicode code point64
(the unicode code point of the character beforeA
, which is@
) pluslen(word)
. We then add a single space toW
once all the words of a sentence have been exhausted, and when all the sentences in a paragraph are exhausted, we add a.
followed by a single space.Finally, after the entire input has been gone through,
W
is output tostdout
as the deciphered message.