Last active
August 29, 2015 14:18
-
-
Save alphaKAI/1da14ae1ccc3d84d316e to your computer and use it in GitHub Desktop.
斜辺が1000以下のピタゴラス数を求めるプログラム (ベンチマーク用)
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
| #encoding:utf-8 | |
| max = 1000 | |
| class Pythagoras | |
| def initialize(a, b, c) | |
| @a = a | |
| @b = b | |
| @c = c | |
| end | |
| def array | |
| [@a, @b, @c] | |
| end | |
| end | |
| array = [] | |
| (1..max).each do |a| | |
| (1..a).each do |b| | |
| (1..b).each do |c| | |
| if a*a == b*b + c*c | |
| array << Pythagoras.new(a, b, c) | |
| end | |
| end | |
| end | |
| end | |
| p array.map{|x| x.array} |
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
| Rubinius: | |
| rubinius 2.5.2.c145 (2.1.0 50aa7356 2015-04-07 3.5.1 JI) [x86_64-darwin14.1.0] | |
| ./rubinius/bin/rbx pythagoras.rb 7.38s user 0.13s system 118% cpu 6.318 total | |
| CRuby: | |
| ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14] | |
| ruby pythagoras.rb 21.36s user 0.10s system 99% cpu 21.563 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment