Skip to content

Instantly share code, notes, and snippets.

@ashleighbasil
Created February 15, 2021 07:38
Show Gist options
  • Save ashleighbasil/1edcd0e746c5a2df0d37c582ae7b4420 to your computer and use it in GitHub Desktop.
Save ashleighbasil/1edcd0e746c5a2df0d37c582ae7b4420 to your computer and use it in GitHub Desktop.
Solution to Cassidoo make sentence puzzle :D :D :D
def make_sentence(string, words, current=[], final=[]):
# Base case
if string == '':
final.append(current)
for word in words:
if string[:len(word)] == word:
make_sentence(
string[len(word):],
words,
current + [word],
final
)
return [' '.join(s) for s in final]
string = "penpineapplepenapple"
words = ["apple", "pen", "applepen", "pine", "pineapple"]
print(make_sentence(string, words))
# result: ['pen pine apple pen apple', 'pen pine applepen apple', 'pen pineapple pen apple']
# :D :D :D
@ashleighbasil
Copy link
Author

Someone please talk to me <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment