Created
August 16, 2012 13:20
-
-
Save myokoym/3370047 to your computer and use it in GitHub Desktop.
Problem033
This file contains 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
#! ruby | |
buns = [] | |
10.upto(99) do |i| | |
i.upto(99) do |j| | |
buns << [i, j] | |
end | |
end | |
results = [] | |
buns.each do |bun| | |
1.upto(9) do |i| | |
x1, x2 = bun[0].to_f, bun[1] | |
y1, y2 = bun[0].to_s.delete(i.to_s).to_f, bun[1].to_s.delete(i.to_s).to_i | |
if x1 != x2 && x1 != y1 && x1 / x2 == y1 / y2 | |
results << bun | |
end | |
end | |
end | |
p result | |
bunshis = [] | |
bunbos = [] | |
results.each {|a| bunshis << a[0]; bunbos << a[1] } | |
bunshi = bunshis.inject(:*) | |
bunbo = bunbos.inject(:*) | |
require "mathn" | |
p bunshi / bunbo | |
p Rational(bunshi, bunbo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment