|
Hey! After completing project 5 (WordScramble) i wanted to improve it with showing the total amount of points you can achive with each word. Iv been trying to loop through all the words using the rootword to get all "possible" words from the word array. So i would like the loop to put all possible words that can be created from the letters from a specific word to be put into an array. However i cannot get it to work.
This is how far i have come so far. I could need some tips on how to do this. =) |
|
I tried some for loops trying to remove words that don't include the rootword's characters, but the iterating between all words and for each character takes ages..moreover it was not very accurate.. |
|
I can give you a function that will give you all possible permutations of a string, you can modify it for an array of String, you can give it a try i guess ...
|
|
Amit's function is fantastic! But only solves part of the problem! Come for the SwiftUI lessons, get a bonus maths lesson free!(Please double check my maths!) An 8 letter word ("gasoline") will have 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 permutations. Roughly 40,320 ways to But the game allows you to create words of any size between 3 and 8 letters. A 7 letter word will have 7 x 6 x 5 x 4 x 3 x 2 x 1 permutations. Roughly 5,038 ways to permutate seven letters. How many ways can you combine seven letters from a set of eight letters? If you exclude one letter from an 8-letter word, you're left with seven letters. And there are 8 possible letters to exclude, so 8. There are 8 possible ways to pick seven letters from a set of 8. -g asoline 8 x 7! = 40,320 additional unvalidated seven letter words missing from Amit's function. Combinations and PermutationsHow many ways can you permutate six letters from a set of eight letters? This is the k-permutations of n-elements problem. I think that's about 20,000 6-letter permutations, each of which needs to be run throught Amit's function to find possible six letter words. For each of the 20,000 6-letter permutations, you'll get a list of 6 x 5 x 4 x 3 x 2 x 1 = 720 possible words. That's 720 x 20,000 more unvalidated six letter words you'll have to run through the dictionary. Then you'll need to gronkulate the 5-letter, 4-letter, and 3-letter calculations. Yikes! Someone can finish this problem. I have a headache! PS: High probability (VERY high) I borked the concepts of permutations and combinations. Please correct me! |
|
Thanks for your replies! I will see if i can do something with this and come back. What i have been trying to do before is to use the "isPossible" func from Paul to check each word in the array to the rootword and check if it is possible. And if the function returns true, the word, is added into an array, in my mind it should work, but it is not. x)
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.