Triangle inequality and Hamming Distance The Question I am trying to answer is:
let $x,y,z$ be binary codes with the same number of bits, give an example or prove that the following cannot happen.
$dH(x,y)=5$, $dH(y,z) = 2$ and $dh(x,z) = 6$, where $dH$ is the Hamming distance between the codes.
I have applied the triangle inequality which confirms that this may be possible as $dH(x,z) < dh(x,y) + dH(y,z)$. However I cannot find any examples. I appears to me that the only way to obtain this scenario would be for $dH(y,z)$ to be an odd number rather than an even number. I have written some code to try and generate an example but cannot obtain any examples so i am sure this is not possible, can anyone help me confirm this is or is not the case?
 A: Assume without loss of generality that $y$ is made of zeroes; $y = 00000...$, and that $dH(y,z) = 2$. Let $i, j$ denote the positions in which $z_i = z_j = 1$ (the two places where $z \neq y$). Assume $dH(x,y) = 5$. So $x$ has $5$ positions that are $1$. There are three cases: 
1) If $x_i = x_j = 1$, then $dH(x,z) = 3$ Because $x, z$ only differ in the positions that are 1 in $x$ and not in $z$, and there are 3 of them.
Example : $x = 11\color{red}{111}00..$, $z = 11\color{blue}{000}00..$
2) $x_i = 1$, and $x_j = 0$, or  $x_i = 0$, and $x_j = 1$, in both cases $dH(x,z) = 4$ 
Example : $x = 1\color{blue}{0}\color{red}{111}00..$, $z = 1\color{red}{1}\color{blue}{000}00..$
3) $x_i = x_j = 0$, in this case $dH(x,z) = 7$ - as there are 5 positions where $x$ is 1 and $z$ is zero, and 2 more where $x$ is 0 and $z$ is 1. 
Example : $x = \color{blue}{00}\color{red}{11111}00..$, $z = \color{red}{11}\color{blue}{00000}00..$
In none of the cases is $dH(x,z) = 6$, so you get your contradiction. 
A: Let two numbers of length $n$, $x$ and $y$, have $a$ and $b$ ($a\le b$) $1$'s in common with a third number of length $n$, $0\dots0$.
Let the number of $1$'s $x$ and $y$ have in common be $c$.
We know $0\le c\le a$, and also that the number of $1$'s that $a$ doesn't have in common with $b$ is $a-c$.
The number of $1$'s that $b$ doesn't have in common with $a$ is $b-c$. 
So $dH(x,y)=(a-c)+(b-c)=a+b-2c$.
In your question $a=2$, $b=6$, and $c\in\{0,1,2\}$, and so it is impossible for $dH(x,y)=5$.
Note that if you flip a bit in $z$ and you flip the same bit in both $x$ and $y$, then the Hamming numbers don't change, and swapping bit columns (i.e. swapping $(x_i,y_i,z_i)\leftrightarrow(x_j,y_j,z_j)$) doesn't change the Hamming number either.
To complete the proof, any set of numbers created from $0\dots0$ using the above transforms, with corresponding numbers having appropriate Hamming numbers, has the same Hamming numbers, and $dH(x,y)$ is invariant.
