import hashlib


def _hash_gene(gene, length=6):
    """Get the first letters of the SHA-1 digest of the gene."""

    encoded = sum(
        v * 4 ** i for i, v in enumerate(gene)
    ).to_bytes(13, byteorder='big')
    digest = hashlib.sha1(encoded).hexdigest()
    return digest[0:length]