Introduction
Some ASCII characters are just so expensive these days...
To save money you've decided to write a program that encodes expensive characters using inexpensive ones.
However, character prices change frequently and you don't want to modify your program every time you need to encode or decode a different character! You'll need a more dynamic solution.
Challenge
Your task is to write two programs: an encoder and a decoder.
The encoder should accept a list of five inexpensive characters, and a single expensive character.
It should output a single string made up of the inexpensive characters, that encodes the expensive character.
This string may not be longer than 4 characters, to remain inexpensive. However, it does not have to use all of the inexpensive characters in the encoding and encodings may be of different lengths.
The decoder should accept the string outputted by the encoder, and output the expensive character.
The decoder shall accept no input other than the encoded string. It must work, unmodified, from the encoder's output for any (valid) combination of inputs. In other words, your decoder program doesn't know which characters are expensive or inexpensive.
Scoring
Shortest combined code wins!
Notes
All characters will be either uppercase letters
[A-Z]
, lowercase letters[a-z]
, or numbers[0-9]
.The list of inexpensive characters won't contain duplicates. No character will be both inexpensive and expensive.
The encoder and decoder don't have to be written in the same language, but they can be. You may write a program or a function.
Input and output may be in any reasonable format for your language.
The two programs may not share any variables or data.
Summary
Input of some inexpensive characters and an expensive character is given to encoder.
Encoder outputs a string of inexpensive characters, encoding the expensive character.
Decoder is given the encoder's output, and outputs the expensive character.
Examples
Input: a, b, c, d, e
f
Encoder Possibilities: a
eeee
caec
Decoder: f
Input: a, b, c, d, e
h
Encoder Possibilities: bc
cea
eeaa
Decoder: h
Input: q, P, G, 7, C
f
Encoder Possibilities: 777
P7
PPCG
Decoder: f