Continued fraction/Arithmetic/Construct from rational number: Difference between revisions
Content added Content deleted
(Added Forth entry) |
(Added Quackery.) |
||
Line 1,959: | Line 1,959: | ||
print(list(real2cf(Fraction(13, 11)))) # => [1, 5, 2] |
print(list(real2cf(Fraction(13, 11)))) # => [1, 5, 2] |
||
print(list(islice(real2cf(2 ** 0.5), 20))) # => [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]</lang> |
print(list(islice(real2cf(2 ** 0.5), 20))) # => [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]</lang> |
||
=={{header|Quackery}}== |
|||
<lang Quackery> |
|||
[ $ "bigrat.qky" loadfile ] now! |
|||
[ [] unrot |
|||
[ proper |
|||
2swap join unrot |
|||
over 0 != while |
|||
1/v again ] |
|||
2drop ] is cf ( n/d --> [ ) |
|||
' [ [ 1 2 ] |
|||
[ 3 1 ] |
|||
[ 23 8 ] |
|||
[ 13 11 ] |
|||
[ 22 7 ] |
|||
[ -151 77 ] |
|||
[ 14142 10000 ] |
|||
[ 141421 100000 ] |
|||
[ 1414214 1000000 ] |
|||
[ 14142136 10000000 ] |
|||
[ 31 10 ] |
|||
[ 314 100 ] |
|||
[ 3142 1000 ] |
|||
[ 31428 10000 ] |
|||
[ 314285 100000 ] |
|||
[ 3142857 1000000 ] |
|||
[ 31428571 10000000 ] |
|||
[ 314285714 100000000 ] ] |
|||
witheach |
|||
[ do over echo say "/" |
|||
dup echo |
|||
say " = " |
|||
cf echo cr ]</lang> |
|||
{{out}} |
|||
<pre>1/2 = [ 0 2 ] |
|||
3/1 = [ 3 ] |
|||
23/8 = [ 2 1 7 ] |
|||
13/11 = [ 1 5 2 ] |
|||
22/7 = [ 3 7 ] |
|||
-151/77 = [ -2 25 1 2 ] |
|||
14142/10000 = [ 1 2 2 2 2 2 1 1 29 ] |
|||
141421/100000 = [ 1 2 2 2 2 2 2 3 1 1 3 1 7 2 ] |
|||
1414214/1000000 = [ 1 2 2 2 2 2 2 2 3 6 1 2 1 12 ] |
|||
14142136/10000000 = [ 1 2 2 2 2 2 2 2 2 2 6 1 2 4 1 1 2 ] |
|||
31/10 = [ 3 10 ] |
|||
314/100 = [ 3 7 7 ] |
|||
3142/1000 = [ 3 7 23 1 2 ] |
|||
31428/10000 = [ 3 7 357 ] |
|||
314285/100000 = [ 3 7 2857 ] |
|||
3142857/1000000 = [ 3 7 142857 ] |
|||
31428571/10000000 = [ 3 7 476190 3 ] |
|||
314285714/100000000 = [ 3 7 7142857 ] |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |