Last active
September 23, 2015 09:17
-
-
Save koki-h/bb697acb2948fd8c19e8 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 029 C問題の回答
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
| #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