清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # Calculate the Fibonacci to 'x' number of places and return it as an array def Fibonacci(limit) # Creates a new array array = Array . new # Our first number num1 = 1 # Our second number num2 = 1 # Our next number nextNum = 0 # Loop through until we reach our limit # NOTE: we need to subtract 2 because we will add two numbers to the beginning later while nextNum < (limit - 2 ) # Our third number will be made by adding our first and second number together num3 = num1 + num2; # Our new first number is our old second number num1 = num2; # Our new second number is our old third number num2 = num3; # Insert our new number into our array array.insert(nextNum, num3) # This will be our next number nextNum += 1 # You can also use: nextNum = nextNum.next # Exit the 'while' loop end # Insert the number 1 into the beginning of our array array.insert( 0 , 1 ) # Insert the number 1 into the 2nd position of our array array.insert( 1 , 1 ) # Return our array return array # Exit the method end |