File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
projects/find-nth-fibonacci Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " find-nth-fibonacci"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+ [dependencies ]
Original file line number Diff line number Diff line change 1+ // use std::{}
2+
3+ // ============================================================================
4+
5+ const GOLDEN_RATIO : f64 = 1.618033988749895 ; // known as φ (phi)
6+
7+ fn main ( ) {
8+ // just clear the console for us
9+ print ! ( "\x1b [2J\x1b [1;1H" ) ;
10+
11+ let input = 6 ;
12+
13+ let nth_of_input = calculate_nth_fibonacci ( input) ;
14+
15+ println ! ( "the {input}th of fibonacci sequence is : {nth_of_input}" ) ;
16+ }
17+
18+ fn calculate_nth_fibonacci ( nth : u32 ) -> f64 {
19+ let square_of_five: f64 = ( 5 as f64 ) . sqrt ( ) ;
20+
21+ let nth: f64 = nth. into ( ) ;
22+
23+ ( GOLDEN_RATIO . powf ( nth) - ( 1.0 - GOLDEN_RATIO ) . powf ( nth) ) / square_of_five
24+ }
You can’t perform that action at this time.
0 commit comments