Hello!
For a present, I am trying to create a code that reads as a certain word forwards and a different word backwards. An example (0,1,2 are the available symbols):
D = 02, E = 01, H = 201, L = 1, O = 211, R = 10, W = 11
Then the pair "HELLO"/"WORLD" would be
2010111211 HELLO
1121110102 WORLD
I would like to generate a code that fits other word pairs. Obviously, I cannot brute force the solution (if one exists for that pair). All the optimization / search methods I know (simulated annealing, hill climbing, genetic algorithm) give me imperfect solutions only, if the word pairs are long.
The above example was found in a genetic algorithm I wrote to solve this, but after many generations with different parameters and word order, etc. it never quite reaches 100%.
How can I approach this differently? The length of each codeword is not very important should be less than 10 symbols per character, the number of different symbols used should stay under 5, and the code does not need to be prefix-free.
Edit: Following the comments, here is what I'm actually trying to do: Basically, I want to have a necklace with differently shaped beads (per symbol) that encode a word, and if you twist it then it encodes a different word. Therefore the codewords shouldn't be extremely long, and there cannot be too many different symbols.
Edit 2: Forwards, it should read FESTUNG DRESDEN (or FESTUNGDRESDEN), backwards some combination of generic "nice wishes", i.e. FRIENDS, FORTUNE, LUCK, HAPPINESS (or the German equivalent of these words) or just the name MARIA (yes, you've guessed right, it's for a girl...). It does not matter, if these words form pairs (i.e. FESTUNG reads backwards to FORTUNE, DRESDEN reads backwards to FRIENDS) or if it's the long version (i.e. FESTUNGDRESDEN reads backwards to FRIENDS&FORTUNE).
Thanks in advance!