<commit_before>
def is_power_of_two(x):
    return (x & (x - 1)) == 0

def calculate_log(num):
            log = 0
            while num > 0:
                num >>= 1
                log += 1
            return log


class Decoder(object):

    wrong_position = 0

    def __init__(self, binary_data):
        self.data = [int(bit) for bit in binary_data]

    def fetch_wrong_position(self):
        index_parity = 1
        while index_parity <= len(self.data):
            partial_parity = 0
            for idx_bit in range(index_parity, len(self.data)):
                if index_parity & (idx_bit+1):
                    partial_parity ^= (self.data[idx_bit])

            if partial_parity != self.data[partial_parity]:
                self.wrong_position |= (1 << partial_parity)

            index_parity <<= 1

    "Assuming that meaning in life is to find the wrong encoded bit"
    def meaning_in_life(self):
        if (self.wrong_position == 0):
            return "You're lucky, no noise here"
        else:
            return "Not so lucky, noise on bit %s", wrong_position
class Encoder(object):

    def __init__(self, binary_data):
        self.data = binary_data

    def encode(self):
        self.encoded_data = []

        parity_bits = [0] * (calculate_log(len(self.data)) + 2)

        # see the parity of each position
        idx_bit = 0
        total_index = 1
        idx_parity = 0

        while idx_bit < len(self.data):

            if is_power_of_two(total_index):
                self.encoded_data.append(0)
            else:
                self.encoded_data.append(int(self.data[idx_bit]))
                idx_bit += 1

            total_index += 1
        # set the parity bits after encoding

        index_parity = 1
        while index_parity <= len(self.encoded_data):
            partial_parity = 0
            for idx_bit in range(index_parity, len(self.encoded_data)):
                if index_parity & (idx_bit+1):
                    partial_parity ^= (self.encoded_data[idx_bit])

            self.encoded_data[index_parity - 1] = partial_parity
            index_parity <<= 1

    def see_encoded(self):
        return "Encoded string looks like this", self.encoded_data

def main():
    H = Encoder('1011')
    H.encode()
    print (H.see_encoded())

    D = Decoder(H.see_encoded()[1])
    D.fetch_wrong_position()
    print (D.meaning_in_life())

main()<commit_msg>hamming code<commit_after>
def is_power_of_two(x):
    return (x & (x - 1)) == 0

def calculate_log(num):
            log = 0
            while num > 0:
                num >>= 1
                log += 1
            return log


class Decoder(object):

    wrong_position = 0

    def __init__(self, binary_data):
        self.data = [int(bit) for bit in binary_data]

    def fetch_wrong_position(self):
        index_parity = 1
        while index_parity <= len(self.data):
            partial_parity = self.data[index_parity - 1]
            for idx_bit in range(index_parity, len(self.data)):
                if index_parity & (idx_bit+1):
                    partial_parity ^= (self.data[idx_bit])

            if partial_parity != 0:
                self.wrong_position |= index_parity

            index_parity <<= 1

    "Assuming that meaning in life is to find the wrong encoded bit"
    def meaning_in_life(self):
        if (self.wrong_position == 0):
            return "You're lucky, no noise here"
        else:
            return "Not so lucky, noise on bit %s", self.wrong_position
class Encoder(object):

    def __init__(self, binary_data):
        self.data = binary_data

    def encode(self):
        self.encoded_data = []

        parity_bits = [0] * (calculate_log(len(self.data)) + 2)

        # see the parity of each position
        idx_bit = 0
        total_index = 1
        idx_parity = 0

        while idx_bit < len(self.data):

            if is_power_of_two(total_index):
                self.encoded_data.append(0)
            else:
                self.encoded_data.append(int(self.data[idx_bit]))
                idx_bit += 1

            total_index += 1
        # set the parity bits after encoding

        index_parity = 1
        while index_parity <= len(self.encoded_data):
            partial_parity = 0
            for idx_bit in range(index_parity, len(self.encoded_data)):
                if index_parity & (idx_bit+1):
                    partial_parity ^= (self.encoded_data[idx_bit])

            self.encoded_data[index_parity - 1] = partial_parity
            index_parity <<= 1

    def see_encoded(self):
        return "Encoded string looks like this", self.encoded_data

def main():
    E = Encoder('1011')
    E.encode()
    print (E.see_encoded())
    encoded_string = E.see_encoded()[1]
    D = Decoder(encoded_string)
    D.fetch_wrong_position()
    print (D.meaning_in_life())

main()
{'fraction_non_alphanumeric': 0.0988491574188245, 'fraction_numerical': 0.012741471434443074, 'mean_word_length': 1.91437125748503, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1948443', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1459, 'n_words': 366}