Encoding
Initialize the step count variable C to 1.
Write the binary representation of the number without the leading "1" to the beginning of the code.
Let M be the number of bits written in step 2.
If M is not 0, increment C, repeat from step 2 with M as the new number.
Write C "1" bits and a "0" to the beginning of the code.
The code begins:
Number |
Encoding |
Implied probability |
0 |
0 |
1/2 |
1 |
10 |
1/4 |
2 |
110 0 |
1/16 |
3 |
110 1 |
1/16 |
4 |
1110 0 00 |
1/128 |
5 |
1110 0 01 |
1/128 |
6 |
1110 0 10 |
1/128 |
7 |
1110 0 11 |
1/128 |
8 |
1110 1 000 |
1/256 |
9 |
1110 1 001 |
1/256 |
10 |
1110 1 010 |
1/256 |
11 |
1110 1 011 |
1/256 |
12 |
1110 1 100 |
1/256 |
13 |
1110 1 101 |
1/256 |
14 |
1110 1 110 |
1/256 |
15 |
1110 1 111 |
1/256 |
16 |
11110 0 00 0000 |
1/4096 |
17 |
11110 0 00 0001 |
1/4096 |
To decode a Levenshtein-coded integer:
Count the number of "1" bits until a "0" is encountered.
If the count is zero, the value is zero, otherwise Start with a variable N,
set it to a value of 1 and repeat count minus 1 times:
Read N bits, prepend "1", assign the resulting value to N
So to encode the give coordinates would equate to 01110001 11100001 11000110 00000010 11011110 011000
Converted to hexadecimal this gives 71 E1 C6 02 DE 60
and now for a puzzle as the cache is not at the given location
N54 52.(london - darlington) * (sunderland - london) * (durham - edinburgh) - (newcastle - london) W001 37.(pelton - london) * (ouston - pelton) * (london - sunderland) * (durham - edinburgh) - (pelton - london)
You can validate your puzzle solution with certitude.