Created
June 14, 2019 18:06
-
-
Save hrisheekeshr/4ad93ff8ef31867452898eec775a329b to your computer and use it in GitHub Desktop.
Substing Cost Optimimisation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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