# 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 is ab=c. Add this string to the coded message.
• 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 be a==, meaning that all as must be replaced with ='s.

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 , so shortest answer in bytes wins!

• oh yeah, sorry! editting – pydude Apr 5 '17 at 21:13
• What about transitivity and circularity, e.g. "massega","e=a","a=e" and the like? – Jonathan Allan Apr 5 '17 at 21:28
• bits of decoding info do not decode each other. Only the message is affected by the decoding information. – pydude Apr 5 '17 at 21:30
• also, only one replacement will be given for each character, e.g. no "io,"i=u","i=g" – pydude Apr 5 '17 at 21:32
• Thanks, I suggest adding this information to the specification. – Jonathan Allan Apr 5 '17 at 21:33

# Jelly, 19 bytes

ḊṖ⁼“=”
ÇÐfKm2yÇÐḟF$ Try it online! ### How? ḊṖ⁼“=” - Link 1, isMappngElement?: string Ḋ - dequeue Ṗ - pop “=” - char-list,['='] ⁼ - equal? ÇÐfKm2yÇÐḟF$ - Main link: list of strings
Ðf          - filter keep:
Ç            -     last link (1) as a monad
K         - join with spaces
m2       - modulo 2 slice (every other character)
$- last two links as a monad: Ðḟ - filter discard: Ç - last link (1) as a monad F - flatten y - translate right according to the mapping of left  • Very interesting, what does m2 "modulo 2 slice" mean? – Magic Octopus Urn Apr 6 '17 at 17:06 • m is a dyadic atom that takes every right-th element of left*. Here, for example, ['x','=','y','<space>','a','=','b']m2 would yield ['x','y','a','b']. (* unless right is zero when it appends a reflection instead.) – Jonathan Allan Apr 6 '17 at 17:15 # Python 3, 98 lambda l:''.join(x*('='!=x[1:-1])for x in l).translate({'='!=x[1:-1]or ord(x[0]):x[2:]for x in l})  This lambda function receives a list of strings (input) and returns a string (the decoded message). Examples: >>> f(['ta', 'y=s', 'y', 'a=e', 'b=t', 'b', ' ', 'j', 'j=1']) 'test 1' >>> f(['z=p', 'zota', 'g=e', 'yugkb', 'y=t', 'u=o', 'k=s', 'li', 'fg', 'b==']) 'potatoes=life' >>> f(['p', '=', '==n', 'ot', 'p=a', 'hiz', 'i=e', 'z=r']) 'another'  • Do you need :-1 or will :2 work? – DSM Apr 6 '17 at 0:35 • @DSM I think it's needed because '=' == x[1:2] will be true for x = 'a=bc', which is not a part of the encoding scheme – vaultah Apr 6 '17 at 0:43 • Ahh, good point! – DSM Apr 6 '17 at 0:44 # Haskell, 85 bytes f x=[(a,b)|[a,'=',b]<-x] h x=map(\v->maybe v id$lookup v$f x)$concat[c|c<-x,[]==f[c]]


### Usage

>h ["p","=","==n","ot","p=a","hiz","i=e","z=r"]
>"another"


### Description

f creates a lookup table.

concat[c|c<-x,[]==f[c]] extracts the message.

map(\v->maybe v id$lookup v$f x) perfoms the lookup.

# JavaScript (ES6), 87 bytes

(l,s='',d={})=>l.map(v=>/.=./.test(v)?d[v[0]]=v[2]:s+=v)&&[...s].map(c=>d[c]||c).join


<input id=a oninput="try{b.innerText=((l,s='',d={})=>l.map(v=>/.=./.test(v)?d[v[0]]=v[2]:s+=v)&&[...s].map(c=>d[c]||c).join)(eval([${a.value}]))}catch(e){}"/> <p id=b /> # Retina, 848277 74 bytes Takes a comma-separated list as input. Note the trailing newline ^|$
,,
+,(.=.)(,.*)
$2$1
M!&(.).*,,.*\1=.|.+,
%(.).*,$|.*(.)$1$2 \n|,  Try it Online! Explanation: First, we move all expressions of the form .=. to the end of the string and separate these from the message with a double comma (,,). This is so that in the next step, we can find all encodings by checking if each character ahead of the ,, has a matching =. afterwards. This is achieved by M!&(.).*,,.*\1=.|.+, which finds all such matches and places them into a linefeed separated list of strings. We then modify each string to only contain either one unencoded character or the encoded version of the character. Finally we replace all linefeeds and commas with the empty string so that our output is formatted nicely. ## Batch, 188 bytes @echo off set/pm= set c= for %%s in (%m%)do call:c %%s "%%c%%%%~s" not for %%s in (%m%)do call:c %%s "%%c:%%~s%%" echo %c% exit/b :c set s=%~1 if %3 "%s:~1,1%"=="=" call set c=%~2  Explanation: Loops through the list of strings twice (conveniently for likes a string in CSV format). The first time, looks for strings that do not contain an = as the second character, and concatenates them to the result. The second time, looks for strings that do contain an = as the second character, and performs the substitution. (even more conveniently, the substitution is already in Batch format.) # PHP, 116 Bytes <?foreach($_GET as$i)$i[1]=="="&&strlen($i)==3?$r[]=$i:$s.=$i;foreach($r as$l)$s=str_replace($l[0],$l[2],$s);echo$s;


Online Version

# PHP, 89 87 bytes

two versions:

while(a&$s=$argv[++$i])3==strlen($s)&"="==$s[1]?$t[$s[0]]=$s[2]:$m.=$s;echo strtr($m,$t);
while(a&$s=$argv[++$i])preg_match("#^.=.$#",$s)?$t[$s[0]]=$s[2]:$m.=$s;echo strtr($m,$t);


takes input from command line arguments; run with -nr.

• loop through arguments creating parameters for strtr
(translation if argument contains =, message else).
• perform strtr.

# 05AB1E, 31 bytes

vy'=åyg3Q&iyˆyS}})øJÁ¨¹¯KJ.Ás‡


Try it online!

vy              }
'=åyg3Q&                      # See if it's length 3 with an equals in the mid.
iyˆyS                 # If so, add to global array, split into chars.
}
)øJÁ¨         # Transpose, join, and remove the middle =.
¹¯KJ     # Push original input without decryption key.
.Ás‡ # Shift stack to the right, swap and transliterate.
`