Created
April 16, 2016 08:15
-
-
Save lavn0/d596eeb034f396fcfa491efe3a36cc1a to your computer and use it in GitHub Desktop.
toyamarb_q2.rb
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
| #解けてない | |
| module Q2 | |
| def self.strike | |
| strikes = [1, 2] | |
| #5以外を抜くボールの枚数の重複なし組み合わせを求める | |
| result1 = [] | |
| (1..8).each do |n| | |
| strikes.repeated_combination(n).each do |ss| | |
| result1 << ss if ss.inject(:+) == 8 | |
| end | |
| end | |
| #result1 = (1,1,1,1, 1,1,1,1), (1,1,1,1, 1,1,2), ... (2,2,2,2) | |
| #5以外を2枚抜くパターンを求める | |
| result2 = [] | |
| result1.each do |r| | |
| r.permutation(r.count).each do |rr| | |
| result2 << rr | |
| end | |
| end | |
| final = 0 | |
| result2.each{|r| final = final + r.count + 1} | |
| final | |
| end | |
| end | |
| puts "answer : #{Q2.strike}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment