Last active
December 16, 2015 11:19
-
-
Save hamakn/5426742 to your computer and use it in GitHub Desktop.
近似した円周率は円を何角形として扱うことになるのか https://twitter.com/onisci/status/325365096635322368
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
MAX_KETA = 15 | |
# 半径1の正n角系の辺の長さ | |
def edge_length_of_regular_polygon(n) | |
2 * n * Math.sin(Math::PI / n) | |
end | |
n = 6 | |
(0..MAX_KETA).each do |keta| | |
approximation_of_pi = (Math::PI * 10 ** keta).truncate * 1.0 / 10 ** keta | |
while 2 * approximation_of_pi > edge_length_of_regular_polygon(n) | |
n += 1 | |
end | |
puts "#{approximation_of_pi}: #{n}角形" | |
end | |
# 3.0: 7角形 | |
# 3.1: 12角形 | |
# 3.14: 57角形 | |
# 3.141: 94角形 | |
# 3.1415: 237角形 | |
# 3.14159: 1396角形 | |
# 3.141592: 2812角形 | |
# 3.1415926: 9820角形 | |
# 3.14159265: 37942角形 | |
# 3.141592653: 93606角形 | |
# 3.1415926535: 239899角形 | |
# 3.14159265358: 726404角形 | |
# 3.141592653589: 2551887角形 | |
# 3.1415926535897: 7424660角形 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment