Skip to content

Instantly share code, notes, and snippets.

@hinovana
Created March 5, 2013 10:50
Show Gist options
  • Save hinovana/5089477 to your computer and use it in GitHub Desktop.
Save hinovana/5089477 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
## http://job.j-sen.jp/18235/
## 4種類のアルファベット "A,C,G,T" から成るn文字の文字列のシーケンスの中から、
## "AAG"という並びが含まれる文字列を全て列挙するプログラムを書きなさい。
def make_string(n, words)
return [""] if n == 0
strings = []
words.each do |word|
make_string(n-1, words).each do |w|
strings << word + w
end
end
strings
end
words = %w[A G C T]
puts make_string(6, words).delete_if{|x| !x.index("AAG")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment