4. Let $S=\left\{A=\left(a_{1}, \cdots, a_{8}\right) \mid a_{i}=0\right.$ or $1, i=1, \cdots$, 8\}. For two elements $A=\left(a_{1}, \cdots, a_{8}\right)$ and $B=\left(b_{1}\right.$, $\cdots, b_{8}$ ) in $S$, denote
$$
d(A, B)=\sum_{i=1}^{\delta}\left|a_{i}-b_{i}\right|,
$$

and call it the distance between $A$ and $B$. What is the minimum number of elements that can be selected from $S$ such that the distance between any two of them is $\geqslant 5$?
Solution One
(I) First, we point out that the sum of the weights of any two codewords in $\mathscr{D}$ does not exceed 11; otherwise, if
$$
\omega(X)+\omega(Y) \geqslant 12,
$$

then because $12-8=4$, these two codewords must share at least four positions with 1s, and the distance between them
$$
a^{\prime}\left(X, y^{\prime}\right) \leq 8-4=4.
$$

Therefore, $\mathscr{D}$ can contain at most one codeword with a weight $\geqslant 6$. Furthermore, if $\mathscr{D}$ contains a codeword with a weight $\geqslant 7$, then $\mathscr{D}$ can only contain that codeword and the all-zero codeword.
(I) Noting that $5+5-8=2$, we conclude: if $\mathscr{D}$ contains two codewords $A$ and $B$ with a weight of 5, then these two codewords must share at least two positions with 1s. We can further conclude: these two codewords share exactly two positions with 1s. Otherwise, if they share three positions with 1s, then they must also share at least one position with 0s, and the distance between the two codewords
$$
d(A, B) \leqslant 4.
$$

Based on the above discussion, we can conclude: $\mathscr{D}$ can contain at most two codewords with a weight of 5 (otherwise, the third codeword with a weight of 5 must share at least three positions with 1s with either $A$ or $B$).
(1) In summary, $\mathscr{D}$ can contain at most four codewords, one with a weight of 0, one with a weight of 6, and two with a weight of 5. The following example shows that a $\mathscr{D}$ consisting of four codewords can be realized:
$$
\begin{array}{l}
(0,0,0,0,0,0,0,0) \\
(1,1,1,0,0,1,1,1) \\
(1,1,1,1,1,0,0,0) \\
(0,0,0,1,1,1,1,1).
\end{array}
$$

Solution Two First, consider an easier problem: what is the maximum number of codewords of length 7, where the distance between any two is $\geqslant 5$? The answer is: at most two. First, assume $(0,0,0,0,0,0,0)$ is one of the codewords. Then it is impossible to have two more codewords. Otherwise, each of these two codewords would have a weight $\geqslant 5$. However,
$$
5+5-7=3.
$$

So, these two codewords must share at least three positions with 1s. The distance between these two codewords is no more than $7-3=4$.

Now, let's return to the original problem. For codewords of length 8, the first bit can be 0 or 1. Codewords with the same first bit $(a \in\{0,1\})$, the remaining bits form a codeword of length 7, and thus there can be at most two such codewords with a distance $\geqslant 5$. Therefore, there can be at most four codewords of length 8, where the distance between any two is $\geqslant 5$.
An example of "at most four" being achievable is the same as in Solution One.