Created
March 5, 2013 10:50
-
-
Save hinovana/5089477 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- 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