File tree Expand file tree Collapse file tree
project_euler/problem_025 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 159159 * [ Sol1] ( https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_021/sol1.rb )
160160 * Problem 022
161161 * [ Sol1] ( https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_022/sol1.rb )
162+ * Problem 025
163+ * [ Sol1] ( https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_025/sol1.rb )
162164
163165## Searches
164166 * [ Binary Search] ( https://github.com/TheAlgorithms/Ruby/blob/master/searches/binary_search.rb )
Original file line number Diff line number Diff line change 1+ #The Fibonacci sequence is defined by the recurrence relation:
2+ # Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
3+ #Hence the first 12 terms will be:
4+ #
5+ # F1 = 1
6+ # F2 = 1
7+ # F3 = 2
8+ # F4 = 3
9+ # F5 = 5
10+ # F7 = 13
11+ # F8 = 21
12+ # F6 = 8
13+ # F9 = 34
14+ # F10 = 55
15+ # F11 = 89
16+ # F12 = 144
17+ #
18+ #The 12th term, F12, is the first term to contain three digits.
19+ #What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
20+
21+ def solution? ( )
22+ #Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
23+ resultn1 = 1
24+ resultn2 = 1
25+ result = 2
26+ index = 3
27+ num_digits = 1000
28+ value = true
29+ while value
30+ resultn2 = resultn1
31+ resultn1 = result
32+ if ( resultn1 + resultn2 ) . abs . digits . length < num_digits
33+ value = true
34+ else
35+ value = false
36+ end
37+ result = resultn1 + resultn2
38+ index += 1
39+ end
40+ res = index
41+ end
42+
43+ answer = solution? ( )
44+ p answer
45+
You can’t perform that action at this time.
0 commit comments