Last active
December 7, 2015 03:28
-
-
Save yswallow/0e73b1c09a373e30fd20 to your computer and use it in GitHub Desktop.
経済学入門IIで出題された問題(3x4行列4x5個それぞれから和が10になる組み合わせを探す)をRubyで解く
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
| str = File.read("./data.csv") | |
| sets = str.gsub(".","").each_line.map { |s| s.split(" ").map(&:to_i).sort } | |
| #sets.each { |s| p s } | |
| sets.each_with_index do |set,i| | |
| puts "set#{i}" | |
| while i = set.pop | |
| while j = set.shift | |
| if i+j >= 1000 | |
| if i+j == 1000 | |
| puts "%.2f+%.2f=10" % [i/100.0,j/100.0] | |
| else | |
| set.unshift(j) | |
| end | |
| break | |
| end | |
| end | |
| end | |
| end |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
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
| 1.71 0.03 8.98 4.53 4.85 9.92 0.06 5.70 5.39 2.10 4.96 9.42 | |
| 4.44 3.23 2.31 9.71 7.59 5.56 0.27 0.30 0.98 5.67 5.26 6.84 | |
| 5.51 5.88 0.52 5.28 3.31 1.17 0.14 0.15 0.32 5.48 6.15 0.84 | |
| 1.58 3.55 2.71 1.32 2.87 3.75 0.10 2.47 1.54 1.23 1.68 3.17 | |
| 4.22 3.07 2.27 9.27 7.03 6.79 0.12 0.71 0.74 5.09 5.78 5.82 | |
| 2.15 2.27 2.89 0.61 7.12 9.65 0.36 0.53 1.88 9.34 8.88 8.22 | |
| 7.71 5.03 3.14 8.28 9.18 9.48 0.74 1.93 2.81 7.19 6.38 3.80 | |
| 4.42 3.54 7.18 6.99 6.93 6.76 0.84 1.54 7.28 5.54 4.78 5.55 | |
| 1.44 2.28 3.00 0.20 2.54 2.80 1.73 2.19 3.85 1.05 2.39 2.96 | |
| 4.98 2.90 2.88 9.75 9.85 8.17 0.15 0.95 1.31 6.68 6.73 7.67 | |
| 6.06 5.63 1.69 6.36 3.16 1.91 0.85 1.62 1.63 6.25 5.01 1.78 | |
| 3.72 2.00 1.22 8.74 8.23 7.70 0.49 0.74 1.26 3.75 5.22 5.87 | |
| 6.02 5.60 2.63 8.22 8.19 7.54 0.17 2.48 2.44 6.05 6.21 6.60 | |
| 3.15 3.82 4.38 2.95 4.88 7.54 0.47 2.57 4.53 4.94 5.47 5.98 | |
| 0.58 1.69 2.59 1.65 0.98 2.94 0.46 1.98 2.38 0.48 1.79 2.48 | |
| 3.62 3.01 2.48 3.68 2.93 2.53 0.77 1.47 1.69 3.38 3.18 2.28 | |
| 2.89 5.98 8.89 9.49 9.32 9.33 2.64 2.34 2.12 0.68 0.65 1.02 | |
| 7.04 7.59 9.33 9.77 9.50 8.52 0.14 0.67 2.22 5.96 5.58 5.22 | |
| 8.31 7.06 4.51 8.05 7.68 3.71 0.63 0.74 2.23 8.45 6.44 5.29 | |
| 4.67 4.82 3.05 6.36 4.57 5.18 1.69 1.82 2.91 5.82 5.06 4.28 |
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
| set0 | |
| set1 | |
| 5.56+4.44=10 | |
| set2 | |
| set3 | |
| set4 | |
| 5.78+4.22=10 | |
| set5 | |
| set6 | |
| 7.19+2.81=10 | |
| set7 | |
| set8 | |
| set9 | |
| 9.85+0.15=10 | |
| set10 | |
| set11 | |
| 8.74+1.26=10 | |
| set12 | |
| set13 | |
| 5.47+4.53=10 | |
| set14 | |
| set15 | |
| set16 | |
| 9.32+0.68=10 | |
| set17 | |
| 9.33+0.67=10 | |
| set18 | |
| set19 | |
| 5.18+4.82=10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment