#Shrey Gupta #Stone Hill Middle School #Junior Division #Contest #2 2011-2012 #Bits Program #This program was made using the programming language Python version 3.2.2. #Data should be entered using 5 lines. #Each line should contain a string representation of a five character bit string with at most 2 stars. #The stars should represent a 1 or a 0. For example, 1*111 would represent either 10111 or 11111. #This function will remove any extra spaces around the string. def cleanInput(inData): bitData = inData.strip() return bitData #This function will compute the possible bit string values that have at most 2 stars. def bitReplacer(dataX, num): counter = 0 for j in dataX: if j == "*": counter = counter + 1 if counter == 0: print(str(num) + "." + dataX) if counter == 1: outData1 = dataX.replace("*", "0") outData2 = dataX.replace("*", "1") print(str(num) + "." + outData1 + ", " + outData2) if counter == 2: outData1 = dataX.replace("*", "0") outData2 = dataX.replace("*", "1") outData3 = dataX.replace("*", "0", 1) outData3 = outData3.replace("*", "1", 1) outData4 = dataX.replace("*", "1", 1) outData4 = outData4.replace("*", "0", 1) print(str(num) + "." + outData1 + ", " + outData2 + ", " + outData3 + ", " + outData4) #This is where the main program starts. It will take the five inputs and find the possible bit string values for each. print("Input:") data1 = input("1. ") data2 = input("2. ") data3 = input("3. ") data4 = input("4. ") data5 = input("5. ") print(" ") print("Output:") data1 = cleanInput(data1) bitReplacer(data1, 1) data2 = cleanInput(data2) bitReplacer(data2, 2) data3 = cleanInput(data3) bitReplacer(data3, 3) data4 = cleanInput(data4) bitReplacer(data4, 4) data5 = cleanInput(data5) bitReplacer(data5, 5