SHARE
TWEET

Untitled

a guest Sep 15th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. input = %w(a b c)
  2. n = 5
  3.  
  4. def gen_seq(prefix, alphabet)
  5.   alphabet.select { |y| y != prefix[-1] }.map { |y| "#{prefix}#{y}" }
  6. end
  7.  
  8. def gen_seq_for_prefixes(prefixes, alphabet)
  9.   prefixes.reduce([]) { |memo, l| memo.push(*gen_seq(l, alphabet)) }
  10. end
  11.  
  12. (1...n)
  13.     .reduce(input) { |memo| gen_seq_for_prefixes(memo, input) }
  14.     .map { |x| puts "#{x}" }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top