Skip to content

Instantly share code, notes, and snippets.

@timrandg
Last active December 31, 2015 09:59
Show Gist options
  • Save timrandg/7970580 to your computer and use it in GitHub Desktop.
Save timrandg/7970580 to your computer and use it in GitHub Desktop.
all mutations
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