Skip to content

Instantly share code, notes, and snippets.

@moritz
Created August 3, 2012 02:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/3243897 to your computer and use it in GitHub Desktop.
Save moritz/3243897 to your computer and use it in GitHub Desktop.
compute 10k'th digit of sqrt(2) in Perl 6
my Int $i = 2 * 10 ** 20_002;
my Int $sqrt = 10 ** 10_001;
my Int $next_sqrt = ($i div $sqrt + $sqrt) div 2;
loop {
$sqrt = $next_sqrt;
$next_sqrt = ($i div $sqrt + $sqrt) div 2;
last if $sqrt == $next_sqrt;
}
say $sqrt.Str.substr(*-2, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment