Programming Calculate Square Root Continued Fraction

Introduction

Your task is to generate the first 1000 terms in the continued fraction representation of digit-wise sum of square root of 2 and square root of 3.

In other words, produce exactly the following list (but the output format is flexible)

          [2, 6, 1, 5, 7, 2, 4, 4, 1, 11, 68, 17, 1, 19, 5, 6, 1, 5, 3, 2, 1, 2, 3, 21, 1, 2, 1, 2, 2, 9, 8, 1, 1, 1, 1, 6, 2, 1, 4, 1, 1, 2, 3, 7, 1, 4, 1, 7, 1, 1, 4, 22, 1, 1, 3, 1, 2, 1, 1, 1, 7, 2, 7, 2, 1, 3, 14, 1, 4, 1, 1, 1, 15, 1, 91, 3, 1, 1, 1, 8, 6, 1, 1, 1, 1, 3, 1, 2, 58, 1, 8, 1, 5, 2, 5, 2, 1, 1, 7, 2, 3, 3, 22, 5, 3, 3, 1, 9, 1, 2, 2, 1, 7, 5, 2, 3, 10, 2, 3, 3, 4, 94, 211, 3, 2, 173, 2, 1, 2, 1, 14, 4, 1, 11, 6, 1, 4, 1, 1, 62330, 1, 17, 1, 5, 2, 5, 5, 1, 9, 3, 1, 2, 1, 5, 1, 1, 1, 11, 8, 5, 12, 3, 2, 1, 8, 6, 1, 3, 1, 3, 1, 2, 1, 78, 1, 3, 2, 442, 1, 7, 3, 1, 2, 3, 1, 3, 2, 9, 1, 6, 1, 2, 2, 2, 5, 2, 1, 1, 1, 6, 2, 3, 3, 2, 2, 5, 2, 2, 1, 2, 1, 1, 9, 4, 4, 1, 3, 1, 1, 1, 1, 5, 1, 1, 4, 12, 1, 1, 1, 4, 2, 15, 1, 2, 1, 3, 2, 2, 3, 2, 1, 1, 13, 11, 1, 23, 1, 1, 1, 13, 4, 1, 11, 1, 1, 2, 3, 14, 1, 774, 1, 3, 1, 1, 1, 1, 1, 2, 1, 3, 2, 1, 1, 1, 8, 1, 3, 10, 2, 7, 2, 2, 1, 1, 1, 2, 2, 1, 11, 1, 2, 5, 1, 4, 1, 4, 1, 16, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 8, 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 2, 1, 1, 2, 1, 3, 2, 9]                  

Challenge

The following general introduction to continued fraction is taken from the challenge Simplify a Continued Fraction.

Continued fractions are expressions that describe fractions iteratively. They can be represented graphically:

continued fraction

Or they can be represented as a list of values: [a0, a1, a2, a3, ... an]

This challenge is to find out the continued fraction of the digit-wise sum of sqrt(2) and sqrt(3), the digit-wise sum is defined as follows,

Take the digits in the decimal representation of sqrt(2) and sqrt(3), and obtain the sum digit by digit:

                      1.  4  1  4  2  1  3  5  6  2  3 ... +   1.  7  3  2  0  5  0  8  0  7  5 ... =   2. 11  4  6  2  6  3 13  6  9  8 ...                  

Then only keep the last digit of the sum and compile them back to the decimal representation of a real number

                      1.  4  1  4  2  1  3  5  6  2  3 ... +   1.  7  3  2  0  5  0  8  0  7  5 ... =   2. 11  4  6  2  6  3 13  6  9  8 ... ->  2.  1  4  6  2  6  3  3  6  9  8 ...                  

The digit-wise sum of sqrt(2) and sqrt(3) is therefore 2.1462633698..., and when it is expressed with continued fraction, the first 1000 values (i.e. a0 to a999 ) obtained are the ones listed in the introduction section.

Specs

  • You may write a function or a full program. Neither should take inputs. In other words, the function or the program should work properly with no inputs. It doesn't matter what the function or program does if non-empty input is provided.

  • You should output to STDOUT. Only if your language does not support outputting to STDOUT should you use the closest equivalent in your language.

  • You don't need to keep STDERR clean, and stopping the program by error is allowed as long as the required output is made in STDOUT or its equivalents.

  • You can provide output through any standard form.

  • This is code-golf, the lowest number of bytes wins.

  • As usual, default loopholes apply here.

veitchcommoodle1982.blogspot.com

Source: https://codegolf.stackexchange.com/questions/156494/continued-fraction-of-digit-wise-sum-of-square-roots

0 Response to "Programming Calculate Square Root Continued Fraction"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel