Mageia Bugzilla – Attachment 14527 Details for
Bug 33138
ruby new security issues CVE-2024-2728[0-2]
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Fibonacci demo script
fibonacci.rb (text/plain), 811 bytes, created by
Len Lawrence
on 2024-05-04 21:26:03 CEST
(
hide
)
Description:
Fibonacci demo script
Filename:
MIME Type:
Creator:
Len Lawrence
Created:
2024-05-04 21:26:03 CEST
Size:
811 bytes
patch
obsolete
>#!/bin/ruby > >fib = ->(number){ > (number == 0 || number == 1) ? number : fib.(number - 1) + fib.(number - 2) >} > >puts "Using recursion to calculate Fibonacci numbers 11 and 29" >puts fib.call(11) >puts fib.call(29) >puts "Do not run anything larger than 39 or you may be here all day!" ># But the following code should provide a quick response for larger numbers. ># https://www.omnicalculator.com/math/fibonacci#formula-for-n-th-term ># phi is the Golden ratio >SQUAREROOT5 = Math::sqrt(5) >Ï = (1 + SQUAREROOT5) / 2 >puts "The Golden Ratio is #{Ï}" >GOLDENRATIO = Ï > >def fibonacci(number) > Ï = 1 - GOLDENRATIO > a = 1/SQUAREROOT5 > (a * (GOLDENRATIO**number - Ï**number)).to_i >end > >puts sprintf("Term 43 of Fibonacci sequence is %9d", fibonacci(43)) >puts "Any term beyond 70 is difficult to represent exactly."
#!/bin/ruby fib = ->(number){ (number == 0 || number == 1) ? number : fib.(number - 1) + fib.(number - 2) } puts "Using recursion to calculate Fibonacci numbers 11 and 29" puts fib.call(11) puts fib.call(29) puts "Do not run anything larger than 39 or you may be here all day!" # But the following code should provide a quick response for larger numbers. # https://www.omnicalculator.com/math/fibonacci#formula-for-n-th-term # phi is the Golden ratio SQUAREROOT5 = Math::sqrt(5) Ï = (1 + SQUAREROOT5) / 2 puts "The Golden Ratio is #{Ï}" GOLDENRATIO = Ï def fibonacci(number) Ï = 1 - GOLDENRATIO a = 1/SQUAREROOT5 (a * (GOLDENRATIO**number - Ï**number)).to_i end puts sprintf("Term 43 of Fibonacci sequence is %9d", fibonacci(43)) puts "Any term beyond 70 is difficult to represent exactly."
View Attachment As Raw
Actions:
View
Attachments on
bug 33138
:
14526
| 14527 |
14528