fibonacci

Fibonacci calculator with BigIntegers

天涯浪子 提交于 2019-12-31 04:11:48
问题 I'm working on a homework project where I must have the user input a number, and the computer spits out the Fibonacci numbers up to that one. I'd normally be able to do this, with int values, except that for this program, I need to use the BigInteger type instead, because int, long, double, etc. types are too small to hold the values I'll need. So, this is the code I've got. The problem is that it doesn't print the numbers it's supposed to. My imports: import java.math.*; import java.util

Upper limits for fibonnacci

孤街醉人 提交于 2019-12-31 02:31:51
问题 I was reading about the DP version of fibonnaci. In Sedgewick I saw: int[] T = new int[47]; for storage of the previous calculations. Elsewhere I saw that the max input for fibonacci should be less than 92 . It is not clear to me how does these numbers come up? I understand that it has to do with overflow and size of int but I am not clear how we end up with these limits. Any help? 回答1: Well, the fibonacci series grows (approximately) exponentially with a ratio of 1.618 (the golden ratio). If

Generalizing Fibonacci sequence with SICStus Prolog

我的未来我决定 提交于 2019-12-31 01:00:15
问题 I'm trying to find a solution for a query on a generalized Fibonacci sequence (GFS). The query is: are there any GFS that have 885 as their 12th number? The initial 2 numbers may be restricted between 1 and 10. I already found the solution to find the Nth number in a sequence that starts at (1, 1) in which I explicitly define the initial numbers. Here is what I have for this: fib(1, 1). fib(2, 1). fib(N, X) :- N #> 1, Nmin1 #= N - 1, Nmin2 #= N - 2, fib(Nmin1, Xmin1), fib(Nmin2, Xmin2), X #=

How do I prove that two Fibonacci implementations are equal in Coq?

╄→гoц情女王★ 提交于 2019-12-30 05:27:22
问题 I've two Fibonacci implementations, seen below, that I want to prove are functionally equivalent. I've already proved properties about natural numbers, but this exercise requires another approach that I cannot figure out. The textbook I'm using have introduced the following syntax of Coq, so it should be possible to prove equality using this notation: <definition> ::= <keyword> <identifier> : <statement> <proof> <keyword> ::= Proposition | Lemma | Theorem | Corollary <statement> ::= {

Generating Fibonacci series in F#

一曲冷凌霜 提交于 2019-12-30 02:46:07
问题 I'm just starting to learn F# using VS2010 and below is my first attempt at generating the Fibonacci series. What I'm trying to do is to build a list of all numbers less than 400. let fabList = let l = [1;2;] let mutable a = 1 let mutable b = 2 while l.Tail < 400 do let c = a + b l.Add(c) let a = b let b = c My first problem is that on the last statement, I'm getting an error message "Incomplete structured construct at or before this point in expression" on the last line. I don't understand

Haskell Fibonacci Explanation

寵の児 提交于 2019-12-29 07:33:26
问题 I am quite new to Haskell and I'm trying to wrap my head around how the lazy expression of Fibonacci sequences work. I know this has been asked before, but none of the answers have addressed an issue I'm having with visualising the result. The code is the canonical one using zipWith fibs = 0 : 1 : zipWith (+) fibs (tail fibs) I understand the following: zipWith literally zips two lists together tail grabs all but the first element of a list Haskell references 'to-be' computed data as thunks .

Java Program Fibonacci Sequence

↘锁芯ラ 提交于 2019-12-29 06:25:20
问题 I am writing a "simple" program to determine the Nth number in the Fibonacci sequence. Ex: the 7th number in the sequence is: 13. I have finished writing the program, it works, but beginning at the 40th number it begins to delay, and takes longer, and longer. My program has to go to the 100th spot in the series. How can I fix this so it doesn't take so long? This is very basic program, so I don't know all the fancy syntax codes.. my formula is: if n =1 || n = 0 return n; else return F(n-1) +

Recursive Fibonacci memoization

本秂侑毒 提交于 2019-12-28 02:40:07
问题 I need some help with a program I'm writing for my Programming II class at universtiy. The question asks that one calculates the Fibonacci sequence using recursion. One must store the calculated Fibonacci numbers in an array to stop unnecessary repeated calculations and to cut down to the calculation time. I managed to get the program working without the array and memorization, now I'm trying to implement that and I'm stuck. I'm not sure how to structure it. I've Googled and skimmed through

How to print a text notification beside prime fibonacci numbers?

无人久伴 提交于 2019-12-25 09:37:07
问题 This is an assignment from a grade 12 computer science class. The section of the assignment I am having difficulty with reads as follows: Determine which of the first 20 Fibonacci numbers are prime numbers. Put a “this is a prime” text notification in the printout from the Basic challenge. Store the FibPrimes in an array called FibPrimes. Here is what I have attempted: Near the bottom, I attempted to make a loop that would print the text notification "This is a prime" if the given FibNum

Recursion and fibonacci sequence

守給你的承諾、 提交于 2019-12-25 07:20:16
问题 How do I get this code to print all values of the fibonacci sequence of given terms? Right now it prints only the last term #include <stdio.h> int fibonacci(int n){ if (n==2) return 1; else return fibonacci(n-1) + fibonacci(n-2); } int main() { int n; int answer; printf("Enter the number of terms you'd like in the sequence\n"); scanf("%d",&n); answer = fibonacci(n); printf("The answer is %d\n", answer); } 回答1: Your base case is incorrect. When n==2 , you'll call fibonacci(1) and fibonacci(0)