A code that is a word forward and another word back

I am currently trying to create code that reads like a specific word forward and another word backward. Example (0,1,2 - available characters):

D = 02, E = 01, H = 201, L = 1, O = 211, R = 10, W = 11

Then the pair "HELLO" / "WORLD" will be

2010111211 HELLO
1121110102 WORLD

I would like to generate code that is suitable for other pairs of words. Obviously, I cannot redirect the solution (if it exists for this pair). All the optimization / search methods that I know (simulated annealing, rock climbing, genetic algorithm) give me only imperfect solutions if the word pairs are long.

The above example was found in a genetic algorithm that I wrote for this, but after many generations with different parameters and word order, etc. it never reaches 100%.

How can I approach this differently? The length of each codeword is not very important. must be less than 10 characters per character, the number of characters used must remain below 5, and the code must not be prefix.

Edit: Following the comments, this is what I'm actually trying to do: basically, I want to have a necklace with beads of different shapes (per character) that encode a word, and if you twist it, then it encodes another word. Therefore, code words should not be extremely long, and there cannot be too many different characters.

Edit 2: Forward, he should read FESTUNG DRESDEN (or FESTUNGDRESDEN), back, a combination of common “good wishes”, that is FRIENDS, FORTUNE, GOOD LUCK, HAPPINESS (or the German equivalent of these words) or just the name MARIA (yes, you guessed it, this is for a girl ...). It doesn’t matter if these words form pairs (i.e., FESTUNG reads back FORTUNE, DRESDEN reads back to FRIENDS), or if it is a long version (i.e. FESTUNG reads back to FRIENDS & FORTUNE).

Thanks in advance!

+6
language-agnostic encode
source share
2 answers

I tried to convert FESTUNGDRESDEN to MARIA.

I found a possible encoding that does not satisfy all the specified conditions, since one of the letters requires more than 10 characters.

Manual procedure:. Since both words have only one letter ("R"), I have broken both words as follows

---------------> FESTUNGD R ESDEN AIRAM <-------------- 

therefore, keeping the code for R as a palindrome

  cod(FESTUNGD) = cod*(IA) and cod(ESDEN) = cod*(MA) where cod*() means "reading the code backwards" 

Then I divided the task one step further by dividing the codes for E and T

  -----------------------------------> FES(T2) (T1)UNGD R ESD(E3) (E2)(E1)N AIRAM <---------------------------------- 

I think this may be the starting point for the development of a “real” algorithm in the future.

In any case, by doing this, I was able to write down the equations for each encoded char. The only difficult part is “A,” because it is repeated. This leads to the following equation

  cod("FES") & (T2) = cod("ESD") & (E3) 

Acting in a similar way (further splitting the codes of the letter X in X (1) X (2) X (3)), I rewrote the above equation in part and solved it. Not difficult, but tiring.

Result:

 F= 21243 E= 2124 S= 3212 T= 125 U= 1 

N = 4

 G= 3 D= 4321 R= 33 N= 2 M= 24 A= 212123421234212 --> Here is the looong one I= 12343215 So, when you read festungdresden 21243 2124 3212 125 1 2 3 4321 33 2124 3212 4321 2124 2 <-------------------------------------------------------- v backwards is: | | MARIA | 24 212123421234212 33 12343215 212123421234212 -------------------------------------------------> 

I think this solution does not contribute to the development of the algorithm, but I hope it will be for the better love :)

EDIT> FRIENDSHIP

Following the same procedure as above (and the proposal made by Justin L.), I tried the word “friendship”, which is similar to the idea you want to communicate.

In the following table:

 f 434 e 44 s 543 t 22 u 1 n 34 g 5 d 3 r 43 i 345 h 122 p 44434 

Result

  festungdresden 434 44 543 22 1 34 5 3 43 44 543 3 44 34 <----------------------------------------------------- v and backwards is: | | friendship | 434 43 345 44 34 3 543 122 345 44434 ----------------------------------------------> 

Note that the equations for "t", "u" and "h" are independent of the rest of the system. Thus, you can choose any unused combination {3,4,5} (of any length) for them, possibly a necklace with 3 characters. For this you can try

  t -> 4 u -> 54 which results in h -> 454 all 3 are unused and available codes 

Do not forget to upload a photo of the necklace!

Viel Glück!

Edit 1.5 years later

Here are two great photos taken by OP with the results:

enter image description here

enter image description here

+6
source share

If the code does not have to be prefix, and you do not care how many codes are left, then just one character is enough!

You encode each character with a different number from 1, so that as a result, the total number 1s for one word matches the total number for another.

To do this, delete the common characters.

In the case of HELLO and WORLD, you are left with HEL and WRD.

Now you need six different integers that can be grouped into two groups of 3, so the sum of one group = the sum of the others.

One way to do this is to choose odd numbers greater than 1 for one group and even numbers for another (and possibly 1, depending on the number in each group).

For HEL and WRD you choose

{3,5,7} and {1,6,8}.

For ordinary ones, now you can choose numbers not in any group, and you're done! (Although care must be taken for words of different lengths).

I have a feeling that I didn’t understand something.

+2
source share

All Articles