Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #inspired by: http://davidbau.com/archives/2010/03/14/the_mystery_of_355113.html
- #as read on: https://hackerne.ws/item?id=4285531
- #this is PERL for those that don't know.
- #Keith Helbley, 7/24/2012, public domain
- use strict; #force slightly above terrible coding habits
- use warnings; #tell us what is wrong when there are errors
- use Math::Trig;
- $|=1; #flush the output
- my $lasterror = 3;
- for (1..10000){ my $d = $_;
- for (3..40000){ my $n = $_;
- if (abs(($n/$d) - pi) < $lasterror){
- $lasterror = abs(($n/$d) - pi);
- print "\n $n / $d: error $lasterror";
- }
- }
- }
- #output - note abs(error), error is not signed.
- # 3 / 1: error 0.141592653589793
- # 13 / 4: error 0.108407346410207
- # 16 / 5: error 0.0584073464102071
- # 19 / 6: error 0.0250740130768734
- # 22 / 7: error 0.00126448926734968
- # 179 / 57: error 0.00124177639681067
- # 201 / 64: error 0.000967653589793116
- # 223 / 71: error 0.000747583167258092
- # 245 / 78: error 0.000567012564152147
- # 267 / 85: error 0.000416183001557879
- # 289 / 92: error 0.000288305763706198
- # 311 / 99: error 0.000178512175651679
- # 333 / 106: error 8.32196275291075e-005
- # 355 / 113: error 2.66764189404967e-007
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement