Skip to content

Instantly share code, notes, and snippets.

@koki-h
Last active September 23, 2015 09:17
Show Gist options
  • Select an option

  • Save koki-h/bb697acb2948fd8c19e8 to your computer and use it in GitHub Desktop.

Select an option

Save koki-h/bb697acb2948fd8c19e8 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 029 C問題の回答
#AtCoder Beginner Contest 029 C問題の回答
#http://abc029.contest.atcoder.jp/tasks/abc029_c
#問題文
#あなたはスーパーハッカーです。高橋君を攻撃対象に定めたあなたは、
#高橋君のパソコンのパスワードに関して次の事実を突き止めました。
#
# 長さは N 文字である。
# a, b, c 以外の文字は含まれない。
#高橋君のパソコンのパスワードの候補として考えられる文字列をすべて列挙してしまいましょう。
def brute_force(word, length)
if length == 0
puts word
return
end
$chars.each do |c|
brute_force( word + c, length - 1)
end
end
$chars = ['a','b','c']
word_length = gets
brute_force( "", word_length.to_i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment