11
1
Introduction
One day, you were just relaxing in your office in the CIA, when suddenly you see an alert on your computer. Your programs have just intercepted hundreds of coded messages! A quick examination reveals the rule for encoding, but you need a program in order to decode fast.
Challenge
You will be given a list of strings, separated by commas. Each string will contain either:
- Part of the coded message
- It is part of the coded message if it is not in the form
a=b
. Note that it is part of the message if it isab=c
. Add this string to the coded message.
- It is part of the coded message if it is not in the form
- Part of the encoding scheme
- This will be in the form of
a=b
. That means that all a's in the message must be replaced by b's. Note that it could bea==
, meaning that all a`s must be replaced with ='s.
- This will be in the form of
Your program must then output the message, decoded using the scheme found.
Other info:
Your input will only contain commas for separating the strings. It could contain other characters, like !1#, etc. It will not contain uppercase letters. Bits of decoding info do not decode each other. Only the message is affected by the decoding information. Only one replacement will be given for each character, e.g. no "io,"i=u","i=g"
Examples
Input:"ta","y=s","y","a=e","b=t","b"," ","j","j=1"
Output:test 1
Input:"z=p","zota","g=e","yugkb","y=t","u=o","k=s","li","fg","b=="
Output:potatoes=life
Input:"p","=","==n","ot","p=a","hiz","i=e","z=r"
Output:another
This is code-golf, so shortest answer in bytes wins!
oh yeah, sorry! editting – pydude – 2017-04-05T21:13:01.987
What about transitivity and circularity, e.g.
"massega","e=a","a=e"
and the like? – Jonathan Allan – 2017-04-05T21:28:43.4471bits of decoding info do not decode each other. Only the message is affected by the decoding information. – pydude – 2017-04-05T21:30:09.410
1also, only one replacement will be given for each character, e.g. no
"io,"i=u","i=g"
– pydude – 2017-04-05T21:32:11.2601Thanks, I suggest adding this information to the specification. – Jonathan Allan – 2017-04-05T21:33:18.397
Can the input be taken as list of strings in the language's native list format? Like
["a","b","b=c"]
. – Rainer P. – 2017-04-05T21:41:10.130@RainerP. yes, it can. as long as decoding will work if "[" is in one of the strings – pydude – 2017-04-05T21:45:41.907
Is
a=bc
part of the encoding or part of the message? What abouta=
? – Titus – 2017-04-06T00:05:05.250Can output be a newline separated list of characters? – math junkie – 2017-04-06T00:44:03.410
@Titus that would be part of the message, since it is not
a=b
– pydude – 2017-04-06T00:53:58.943@math_junkie that would have to be a no. – pydude – 2017-04-06T00:57:39.043
Can we assume the message can never be all equals signs? – Magic Octopus Urn – 2017-04-06T16:42:26.887