Hamming Distance in Block Parity - hamming-distance

I´m sitting here and I´m not able to solve a problem related to the hamming distance.
I have a block like this:
100
000
111
When I use the vertical redundancy Check now I get:
100-1
000-0
111-1
||| |
011-0
because I add an 1 to each row and column, if I have an odd number of 1´s or I add an 0 to each row and column, if i have an odd number of 0´s.
Now I should have 6 words right?
w1: 1001
w2: 0000
w3: 1110
w4: 1010
w5: 0011
w6: 0011
Are the created (through VRC) bits words too? So are 1000 and 0110 words too?
If I compare the words and check the Hamming Distance, I get an minimal Hamming Distance of 2 (0 should not count, because if the Hamming Distance is 0, the words are the same). E.g. compare w1 and w2.
In our lecture, the professor said, that the Hamming Distance for this example is 3. How can it be 3?!
Were is my mistake? :-(
I hope someone can help me.
Have a great Sunday!

Related

How to compress an integer to a smaller string of text?

Given a random integer, for example, 19357982357627685397198. How can I compress these numbers into a string of text that has fewer characters?
The string of text must only contain numbers or alphabetical characters, both uppercase and lowercase.
I've tried Base64 and Huffman-coding that claim to compress, but none of them makes the string shorter when writing on a keyboard.
I also tried to make some kind of algorithm that tries to divide the integer by the numbers "2,3,...,10" and check if the last number in the result is the number it was divided by (looks for 0 in case of division by 10). So, when decrypting, you would just multiply the number by the last number in the integer. But that does not work because in some cases you can't divide by anything and the number would stay the same, and when it would be decrypted, it would just multiply it into a larger number than you started with.
I also tried to divide the integer into blocks of 2 numbers starting from left and giving a letter to them (a=1, b=2, o=15), and when it would get to z it would just roll back to a. This did not work because when it was decrypted, it would not know how many times the number rolled over z and therefore be a much smaller number than in the start.
I also tried some other common encryption strategies. For example Base32, Ascii85, Bifid Cipher, Baudot Code, and some others I can not remember.
It seems like an unsolvable problem. But because it starts with an integer, each number can contain 10 different combinations. While in the alphabet, letters can contain 26 different combinations. This makes it so that you can store more data in 5 alphabetical letters, than in a 5 digit integer. So it is possible to store more data in a string of characters than in an integer in mathematical means, but I just can't find anyone who has ever done it.
You switch from base 10 to eg. base 62 by repeatedly dividing by 62 and record the remainders from each step like this:
Converting 6846532136 to base62:
Operation Result Remainder
6846532136 / 62 110427937 42
110427937 / 62 1781095 47
1781095 / 62 28727 21
28727 / 62 463 21
463 / 62 7 29
7 / 62 0 7
Then you use the remainder as index in to a base62 alphabet of your choice eg:
0 1 2 3 4 5 6
01234567890123456789012345678901234567890123456789012345678901
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Giving: H (7) d (29) V (21) V (21) v (47) q (42) = HdVVvq
------
It's called base10 to base62, there bunch of solutions and code on the internet.
Here is my favorite version: Base 62 conversion

Extracting Numbers with Commas from String

I want to extract a number of squared meters from a house description column. For example, I used:
df['description'].str.extract('(\d\,\d{1,3}\s?[sS])', expand=True)
to extract 3000 from a string that looks like "The house is 3,000 square meters".
What if I wanted to extract 800 square meters? So a condition that does not involve the comma. How would I add that to the condition. Sorry I looked around and still couldn't figure it out.
I am using str.findall
s=pd.Series(['llll llll llll 100,000.00 lll lll ll ','xyz 800 bgm bhd','80','1,000.00 and 10'])
s.str.findall(r'(?:[,\d]+.?\d*)')
0 [100,000.00]
1 [800]
2 [80]
3 [1,000.00, 10]
dtype: object

A more natural color representation: Is it possible to convert RGBA color to a single float value?

Is it possible to represent an RGBA color to a single value that resembles the retinal stimulation? The idea is something like:
0.0 value for black (no stimulation)
1.0 for white (full stimulation)
The RGBA colors in between should be represented by values that capture the amount of stimulation they cause to the eye like:
a very light yellow should have a very high value
a very dark brown should have a low value
Any ideas on this? Is converting to grayscale the only solution?
Thanks in advance!
Assign specific bits of a single number to each part of RGBA to represent your number.
If each part is 8 bits, the first 8 bits can be assigned to R, the second 8 bits to G, the third 8 bits to B, and the final 8 bits to A.
Let's say your RGBA values are= 15,4,2,1. And each one is given 4 bits.
In binary, R is 1111, G is 0100, B is 0010, A is 0001.
In a simple concatenation, your final number would be 1111010000100001 in binary, which is 62497. To get G out of this, 62497 / 256, round it to an integer, then modulo 16. 256 is 16 to the second power because it is the 2nd position past the first from the right(R would need third power, B would need first power). 16 is 2 to the fourth power because I used 4 bits.
62497 / 256 = 244, 244 % 16 = 4.

Excel: Probability That h Heads Will Appear In n Coin Tosses

I want to calculate the probability that h number of heads will appear in n coin tosses using Excel. For example, the probability of 4 heads appearing in 5 coin tosses. This is the formula:
[n! / h!(n-h)!] * 2^-n
How do I convert this into Excel? What I have is:
=(FACT($A$2)/FACT(B2)*FACT($A$2-B2))*POWER(2,-$A$2)
With A2 representing the number of tosses and B2 the number of heads, but this doesn't seem to work. Well, it works for 4 heads and 5 heads, but that's it. For 0 heads I should be getting 1/32, but instead I get 450. For 1 head I should be getting 5/32, but instead I get 90. I'm really confused. I suspect I'm not multiplying my factorials correctly.
Just this should do:
=(FACT($A$2)/(FACT(B2)*FACT($A$2-B2))*POWER(2,-$A$2))
Your formula just needed brackets in the denominator
=FACT($A$2)/FACT(B2)*FACT($A$2-B2)
doesn't equal
=FACT($A$2)/(FACT(B2)*FACT($A$2-B2))
if it's easier to read
a/b*c = (a*c)/b --> but you want --> a/(b*c)

Why is gray code called reflected code?

I understand that each gray code differs from its preceding code by one bit, but i don't exactly understand why its called reflected. I came across this website https://www.pc-control.co.uk/gray_code.htm, where it says " The gray code is sometimes referred to as reflected binary, because the first eight values compare with those of the last 8 values, but in reverse order", but the first 8 gray codes are not comparable to the last 8 gray codes in reverse order as can be seen from the gray code table on their website. To add to my confusion the gray code table differs from the gray code table on my textbook, for eg gray code for 9 = 1000 on my textbook while on the website its 9 = 1101.
Consider the sequence on the linked page:
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000
Remove the most significant bit and you obtain a nice reflected sequence:
x000
x001
x011
x010
x110
x111
x101
x100
-------- mirror
x100
x101
x111
x110
x010
x011
x001
x000
Please note that the same kind of reflection can be found for Gray sequences of any width.

Resources