Demo entry 6372199

This

   

Submitted by anonymous on May 23, 2017 at 02:45
Language: Python 3. Code size: 1.1 kB.

#!/usr/bin/python
"""
Computes the number of encoded message errors that can be detected but not corrected. 
"""
import itertools

__name__ = '__main__'


def main():
    six_bits = ["".join(seq) for seq in itertools.product("01", repeat=6)]

    patterns = {"000": "000000",
                "100": "110100",
                "010": "011010",
                "110": "101110",
                "001": "101001",
                "101": "011101",
                "011": "110011",
                "111": "000111"}

    count = 0
    for received in six_bits:
        least = 99
        possible_matches = []
        for sent in patterns:
            diff = sum(1 for a, b in zip(patterns[sent], received) if a != b)
            if diff == 0:
                break
            elif diff < least:
                possible_matches = [sent]
                least = diff
            elif diff == least:
                possible_matches.append(sent)
        if len(possible_matches) > 1:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).