Question: Write a Python program that generates all binary strings with a particular Hamming distance from an input string. A binary string is a string of

Write a Python program that generates all binary strings with a particular Hamming distance from an input string. A binary string is a string of some number of 0's and 1's. The Hamming distance between two binary strings is the number of positions in which those two strings differ. For example, the Hamming distance between '010101' and '111110' is 4.

The input for this problem is a binary string and an integer k. Your program will output all binary strings that have Hamming distance k from the input string.

The input for this problem should be read from an input file consisting of some number of lines, each with a binary string and a non-negative integer separated by a space, as in the Sample Input below. Your program should ask for the name of the input file when it runs. You may assume the file format is valid and the binary strings contain only 0 and 1.

You must use recursion to solve this problem. Non-recursive solutions will be penalized 50% of the total marks for Exercise 2.

Contents of Sample Input File

0000 2 11110000 1 0101 5

Sample Output

Strings with distance of 2 from 0000 1100 1010 1001 0110 0101 0011

Strings with distance of 1 from 11110000 01110000 10110000 11010000 11100000 11111000 11110100 11110010 11110001

No strings with distance 5 from 0101

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!