Skip to content

Instantly share code, notes, and snippets.

@hrisheekeshr
Created June 14, 2019 18:06
Show Gist options
  • Save hrisheekeshr/4ad93ff8ef31867452898eec775a329b to your computer and use it in GitHub Desktop.
Save hrisheekeshr/4ad93ff8ef31867452898eec775a329b to your computer and use it in GitHub Desktop.
Substing Cost Optimimisation
cost = 0
initial_string = ""
initial_list = []
def get_all_substrings(input_string):
length = len(input_string)
return [input_string[i:j+1] for i in range(length) for j in range(i,length)]
#This takes the input indefenitely
while True:
input_string = input("Please Enter the String")
if input_string in set(get_all_substrings(initial_string)):
cost+=15
else:
cost+=10
initial_string = initial_string + input_string
print(" Input string : {} \n Current String:{} \n Cost:{}".format(input_string,initial_string,cost))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment