Skip to content

Instantly share code, notes, and snippets.

@gouthamvel
Created September 29, 2011 10:18
Show Gist options
  • Save gouthamvel/1250460 to your computer and use it in GitHub Desktop.
Save gouthamvel/1250460 to your computer and use it in GitHub Desktop.
function to generate sequence from number like 992345x8xx, x being replaced by 0..9
def generate_sequence(str)
list = [str.downcase]
while (num = list.find{|s| s.index 'x'})
list = list + get_list(list.delete num)
end
list
end
def get_list(str)
loc_x = str.index 'x'
list = []
(0..9).each {|i| list << (str[loc_x] = i.to_s and str.dup)}
list
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment