# CCI - Problem 1.5 # Determine whether a string is one edit away from being # the same as a second string (replace, add, remove) s1 = input("Enter a string: ") s2 = input("Enter another string: ") oneAway = True # Equal lengths if (len(s1) == len(s2)): count = 0 for i in range(0,len(s1)): if (s1[i] != s2[i]): count += 1 if (count > 1): oneAway = False # Length differs by 1 elif (len(s1)==len(s2)-1 or len(s2)==len(s1)-1): if (len(s1) < len(s2)): newArray = [] newArray.append(' ') # Copy s1 to new array for c in s1: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s2[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp if (len(s2) < len(s1)): newArray = [] newArray.append(' ') # Copy s2 to new array for c in s2: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s1[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp else: oneAway = False if (oneAway == True): print("true") else: print("false") # CCI - Problem 1.5 # Determine whether a string is one edit away from being # the same as a second string (replace, add, remove) s1 = input("Enter a string: ") s2 = input("Enter another string: ") oneAway = True # Equal lengths if (len(s1) == len(s2)): count = 0 for i in range(0,len(s1)): if (s1[i] != s2[i]): count += 1 if (count > 1): oneAway = False # Length differs by 1 elif (len(s1)==len(s2)-1 or len(s2)==len(s1)-1): if (len(s1) < len(s2)): newArray = [] newArray.append(' ') # Copy s1 to new array for c in s1: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s2[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp if (len(s2) < len(s1)): newArray = [] newArray.append(' ') # Copy s2 to new array for c in s2: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s1[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp else: oneAway = False if (oneAway == True): print("true") else: print("false") # CCI - Problem 1.5 # Determine whether a string is one edit away from being # the same as a second string (replace, add, remove) s1 = input("Enter a string: ") s2 = input("Enter another string: ") oneAway = True # Equal lengths if (len(s1) == len(s2)): count = 0 for i in range(0,len(s1)): if (s1[i] != s2[i]): count += 1 if (count > 1): oneAway = False # Length differs by 1 elif (len(s1)==len(s2)-1 or len(s2)==len(s1)-1): if (len(s1) < len(s2)): newArray = [] newArray.append(' ') # Copy s1 to new array for c in s1: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s2[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp if (len(s2) < len(s1)): newArray = [] newArray.append(' ') # Copy s2 to new array for c in s2: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s1[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp else: oneAway = False if (oneAway == True): print("true") else: print("false") # CCI - Problem 1.5 # Determine whether a string is one edit away from being # the same as a second string (replace, add, remove) s1 = input("Enter a string: ") s2 = input("Enter another string: ") oneAway = True # Equal lengths if (len(s1) == len(s2)): count = 0 for i in range(0,len(s1)): if (s1[i] != s2[i]): count += 1 if (count > 1): oneAway = False # Length differs by 1 elif (len(s1)==len(s2)-1 or len(s2)==len(s1)-1): if (len(s1) < len(s2)): newArray = [] newArray.append(' ') # Copy s1 to new array for c in s1: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s2[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp if (len(s2) < len(s1)): newArray = [] newArray.append(' ') # Copy s2 to new array for c in s2: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s1[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp else: oneAway = False if (oneAway == True): print("true") else: print("false") # CCI - Problem 1.5 # Determine whether a string is one edit away from being # the same as a second string (replace, add, remove) s1 = input("Enter a string: ") s2 = input("Enter another string: ") oneAway = True # Equal lengths if (len(s1) == len(s2)): count = 0 for i in range(0,len(s1)): if (s1[i] != s2[i]): count += 1 if (count > 1): oneAway = False # Length differs by 1 elif (len(s1)==len(s2)-1 or len(s2)==len(s1)-1): if (len(s1) < len(s2)): newArray = [] newArray.append(' ') # Copy s1 to new array for c in s1: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s2[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp if (len(s2) < len(s1)): newArray = [] newArray.append(' ') # Copy s2 to new array for c in s2: newArray.append(c) for i in range(0,len(newArray)): oneAway = True count = 0 for j in range(0,len(newArray)): if(newArray[j] != s1[j]): count += 1 if (count > 1): oneAway = False else: break temp = newArray[i] newArray[i] = newArray[i+1] newArray[i+1] = temp else: oneAway = False if (oneAway == True): print("true") else: print("false")