Metallic ratios: Difference between revisions

→‎{{header|REXX}}: added the REXX computer programming language for this task.
m (→‎{{header|Perl 6}}: style tweaks)
(→‎{{header|REXX}}: added the REXX computer programming language for this task.)
Line 210:
First 15 elements: 1, 1, 10, 91, 829, 7552, 68797, 626725, 5709322, 52010623, 473804929, 4316254984, 39320099785, 358197153049, 3263094477226
Approximated value: 9.10977222864644365500113714088140 - Reached after 20 iterations: 20th/19th element. (zero indexed)</pre>
 
=={{header|REXX}}==
For this task, &nbsp; the elements of the Lucas sequence are zero based.
<lang rexx>/*REXX pgm computes the 1st N elements of the Lucas sequence for Metallic ratios 0──►9. */
parse arg n bLO bHI digs . /*obtain optional arguments from the CL*/
if n=='' | n=="," then n= 15 /*Not specified? Then use the default.*/
if bLO=='' | bLO=="," then bLO= 0 /* " " " " " " */
if bHI=='' | bHI=="," then bHI= 9 /* " " " " " " */
if digs=='' | digs=="," then digs= 32 /* " " " " " " */
numeric digits digs + length(.) /*specify number of decimal digs to use*/
metals= 'platinum golden silver bronze copper nickel aluminum iron tin lead'
approx= 'the approximate value reached after ' /*literals that are used for SAYs. */
!.= /*the default name for a metallic ratio*/
do k=0 to 9; !.k= word(metals, k+1) /*assign the (ten) metallic ratio names*/
end /*k*/
 
do m=bLO to bHI; @.= 1; $= 1 1 /*compute the sequence numbers & ratios*/
r=. /*the ratio (so far). */
do #=2 until r=old; old= r /*compute sequence numbers & the ratio.*/
#_1= #-1; #_2= #-2 /*use variables for previous numbers. */
@.#= m * @.#_1 + @.#_2 /*calculate a number i the sequence. */
if #<n then $= $ @.# /*build a sequence list of N numbers.*/
r= @.# / @.#_1 /*calculate ratio of the last 2 numbers*/
end /*#*/
 
if words($)<n then $= subword($ copies('1 ', n), 1, n) /*extend list if too short*/
L= max(79, length($) ) /*ensure width of title. */
say center(' Lucas sequence for the' !.m "ratio, where B is " m' ', L, "═")
say 'the first ' n " elements are:"
say $
say approx #-1 ' iterations with ' digits() - 1 " decimal digits:"
say format(r,,digs); say
end /*m*/ /*stick a fork in it, we're all done. */</lang>
{{out}}
<pre>
═══════════ Lucas sequence for the platinum ratio, where B is 0 ═══════════
the first 15 elements are:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
the approximate value reached after 2 iterations with 32 decimal digits:
1.00000000000000000000000000000000
 
════════════ Lucas sequence for the golden ratio, where B is 1 ════════════
the first 15 elements are:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
the approximate value reached after 78 iterations with 32 decimal digits:
1.61803398874989484820458683436564
 
════════════ Lucas sequence for the silver ratio, where B is 2 ════════════
the first 15 elements are:
1 1 3 7 17 41 99 239 577 1393 3363 8119 19601 47321 114243
the approximate value reached after 44 iterations with 32 decimal digits:
2.41421356237309504880168872420970
 
════════════ Lucas sequence for the bronze ratio, where B is 3 ════════════
the first 15 elements are:
1 1 4 13 43 142 469 1549 5116 16897 55807 184318 608761 2010601 6640564
the approximate value reached after 34 iterations with 32 decimal digits:
3.30277563773199464655961063373525
 
════════════ Lucas sequence for the copper ratio, where B is 4 ═════════════
the first 15 elements are:
1 1 5 21 89 377 1597 6765 28657 121393 514229 2178309 9227465 39088169 165580141
the approximate value reached after 28 iterations with 32 decimal digits:
4.23606797749978969640917366873128
 
════════════════ Lucas sequence for the nickel ratio, where B is 5 ═════════════════
the first 15 elements are:
1 1 6 31 161 836 4341 22541 117046 607771 3155901 16387276 85092281 441848681 2294335686
the approximate value reached after 25 iterations with 32 decimal digits:
5.19258240356725201562535524577016
 
═══════════════════ Lucas sequence for the aluminum ratio, where B is 6 ═══════════════════
the first 15 elements are:
1 1 7 43 265 1633 10063 62011 382129 2354785 14510839 89419819 551029753 3395598337 20924619775
the approximate value reached after 23 iterations with 32 decimal digits:
6.16227766016837933199889354443272
 
════════════════════════ Lucas sequence for the iron ratio, where B is 7 ════════════════════════
the first 15 elements are:
1 1 8 57 407 2906 20749 148149 1057792 7552693 53926643 385039194 2749201001 19629446201 140155324408
the approximate value reached after 22 iterations with 32 decimal digits:
7.14005494464025913554865124576352
 
══════════════════════════ Lucas sequence for the tin ratio, where B is 8 ═══════════════════════════
the first 15 elements are:
1 1 9 73 593 4817 39129 317849 2581921 20973217 170367657 1383914473 11241683441 91317382001 741780739449
the approximate value reached after 20 iterations with 32 decimal digits:
8.12310562561766054982140985597408
 
═══════════════════════════ Lucas sequence for the lead ratio, where B is 9 ════════════════════════════
the first 15 elements are:
1 1 10 91 829 7552 68797 626725 5709322 52010623 473804929 4316254984 39320099785 358197153049 3263094477226
the approximate value reached after 20 iterations with 32 decimal digits:
9.10977222864644365500113714088140
</pre>