Last active
December 31, 2015 09:59
-
-
Save timrandg/7970580 to your computer and use it in GitHub Desktop.
all mutations
This file contains 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
class Array | |
def expand(master, mut) | |
collection = [] | |
each do |str| | |
c = str.count('.') | |
case | |
when c < mut | |
collection << str + master[str.length] | |
collection << str + '.' | |
when c == mut | |
collection << str + master[str.length] | |
end | |
end | |
collection | |
end | |
def mutagenize_frags(master, mut, len=master.length) | |
var = self.dup | |
while var.first.length < len do | |
var = var.send(:expand, *[master, mut]) | |
end | |
var.sort | |
end | |
end | |
class String | |
def mutagenize_frags(mut,len=self.length) | |
[''].mutagenize_frags(self,mut,len) | |
end | |
end | |
puts "ABCDEF".mutagenize_frags(5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment