Fun with String Permutations
Finding all possible permutations of a group of arrays
So, I've been kicking around some new concepts for Datapresser's Content Generation, based on something called String Permutations.
For example, lets say I had four word groups:
- pronouns (my, your, his, her, our)
- subjects (goat, sailboat, cabin)
- conjunctions (is, is usually, is always)
- adjectives (stinky, leaking, clean)
By analyzing all the possible permutations of these 4 word groups, we can see exactly how much content we can spin from it, and what all the possible permutations are.
In this case, there are 135 possible permutations:
my goat is stinky
my goat is leaking
my goat is clean
my goat is usually stinky
my goat is usually leaking
my goat is usually clean
my sailboat is usually leaking
my sailboat is usually clean
our cabin is always leaking
our cabin is always clean
etc...etc....etc.....
The possible applications of string permutation become apparent when you consider a real-world example, like creating headlines:
So You Want To Meet a Girl
So You Want To Get A Date
So You Want To Ask Out A Woman
So You Want To Ask A Woman Out
So You Want To Get Started Dating
Learn How To Meet a Girl
Learn How To Get A Date
Learn How To Ask Out A Woman
Learn How To Ask A Woman Out
Learn How To Get Started Dating
Find Out The Way To Meet a Girl
Find Out The Way To Get A Date
Find Out The Way To Ask Out A Woman
Find Out The Way To Ask A Woman Out
Find Out The Way To Get Started Dating
It's Easy To Learn How To Meet a Girl
It's Easy To Learn How To Get A Date
It's Easy To Learn How To Ask Out A Woman
It's Easy To Learn How To Ask A Woman Out
It's Easy To Learn How To Get Started Dating
When I first started analyzing the possible permutations of some of my madlib scripts, I was so astounded by the numbers that I assumed I had made a mistake in my coding. After I did the math manually, I realized that I had it right, but the numbers were still astounding.
I have one relatively short madlib script that outputs around 150 words. However, once you take into account number of possible rows in each database it draws from, plus the numerous wildcard sets, that script has approx 42311189564227584000 possible unique permutations.
To give you an idea of how steep the corelation is between input and output, here are some numbers.
Each line represents one word group.
10 <-- first group has 10 words
20 <-- second group has 2 words
100 <-- third group has 5 words
1300 <-- fourth group has 13 words
20800 <-- etc etc etc
166400
998400
10982400
54912000
219648000
1537536000
4612608000
27675648000
110702592000
332107776000
996323328000
3985293312000
15941173248000
95647039488000
382588157952000
2295528947712000
9182115790848000
36728463163392000
110185389490176000
330556168470528000
1322224673882112000
5288898695528448000
10577797391056896000
42311189564227584000
For all you programmers out there, here is how I am calculating permutations (this needs to be threaded to have any production application):
class Array
def sequence(i = 0, *a)
return [a] if i == size
self[i].map {|x|
sequence(i+1, *(a + [x]))
}.inject([]) {|m, x| m + x}
end
end
input = [
["my","your","her","his","our"],
["goat","sailboat","cabin"],
["is","is usually","is always"],
["stinky","leaking","clean"]
]
output = input.sequence
p output.length
p output
Back
Comment:
If you want a clearer view of it, replace the last line of code "p output" with:
output.each do |item|
p item.join(" ")
end
-Musashi
Announcements & News 15 Posts
General news relating to this site
Google Hacking 9 Posts
Oh, the treasures that are to be found on Google!
Links & Points of Interest 9 Posts
Links of interest
Technical 15 Posts
Scripts, Programming, Advanced SEO Techniques
Theory 23 Posts
Off the top of the dome...
Tools & Applications 5 Posts
Tools to help you grow your empire
Twitter 6 Posts
Anything and everything having to do with Twitter
Website Development 4 Posts
Principals and Best Practices for general web development
recent comments:
Andrea_R on Effective and Efficient ways to Mass Install WordpressFunPics on 18 Nasty Ways to Get Backlinks
WebGuyScott on Effective and Efficient ways to Mass Install Wordpress
Jake on Effective and Efficient ways to Mass Install Wordpress
noon on New Datapresser Site Tracker Video
Firelead on Off to Affiliate Summit East
Beerhat on Off to Affiliate Summit East
Navin on Off to Affiliate Summit East
Rob on New Datapresser Site Tracker Video
free on New Datapresser Site Tracker Video
Subscribe to Recent Posts
Subscribe to Featured Databases
Subscribe to Free Downloads
