## fibonacci sequence works, but returns results I do not expect

nterms = int(input("How many terms? ")) n1 = 0 n2 = 1 count = 0 if nterms <= 0: print("Please enter a positive integer") elif nterms == 1: print("Fibonacci sequence upto",nterms,":") print(n1) else: print("Fibonacci sequence upto",n...
more »

## Print the first n numbers of the fibonacci sequence in one expression

So I've been messing around with Python a bit lately and I'm trying to find a way to output the nth number of the fibonacci sequence in a single expression. This is the code that I've written so far: (lambda f: f if f<2 else (f-1)+(f-2))(n) # n =...
more »

## How is this piece of Recursive lambda call in Java working

I recently came across this piece of code in Java. It involves Function and printing fibonacci numbers and it works. public class AppLambdaSubstitution { public static Function<Integer, Integer> Y(Function<Function<Integer, Integer>,...
more »

## HeIp understanding Fibonacci Search

On the internet I only find code for the algorithm but I need understand in form of text first because I have trouble understand things from code only. And other description of the algorithm are very complicated for me (on Wikipedia and other sites)....
more »

## Why does computational time decrease when removing unnecessary items from a list in Python

The past days I've been trying get a better understanding of computational complexity and how to improve Python code. For this I have tried out different functions for calculating Fibonacci numbers, comparing how long the script runs if I make small ...
more »

## Ruby "FloatDomainError: Infinity" when calculating Fibonacci Number

My method for calculating the "length" of a fibonacci number (i.e. number of digits) fails after the 1474th iteration. My way of obtaining the desired result is probably very clumsy, so please let me know if there is a flaw in my approach. I suspec...
more »

## Recursive Fibonacci in Ruby

This week is my first time doing recursion. One of the problems I was able to solve was Fibonacci's sequence to the nth number; it wasn't hard after messing with it for 5 minutes. However, I am having trouble understanding why this works with the c...
more »

## Variable assignment query in python

I am writing Fibonacci code in python. The below solution is mine. While the other below solution is from python.org. Can anyone tell me why it yields a different answer even though the logic of assigning the variables is the same? ...
more »

## Fibonacci sequence works in python, but not in c?

I have the following python code: a, b = 1, 1 for i in range(0, 100): print a a, b = b, a + b It generates this: 1 1 2 3 5 8 etc I wrote the same in c: #include <stdio.h> long long unsigned int a = 1, b = 1; void main(){ for(in...
more »

## printing duplicate of last two number of fibonacci

I am trying to print Fibonacci numbers up to n. The code below prints outs the last number twice for some reason, please help. function fibonacci(n) { let i; const fib = []; fib[0] = 0; fib[1] = 1; for (i=2; i<n; i++) { fib[i] = ...
more »

## ConcurrentHashMap and Fibonacci Numbers - Inconsistent result

I wrote a program for calculating fibonacci numbers recursively, with a ConcurrentHashMap and computeIfAbsent() method: Program works absolutely fine when i used small values like 8,9,10 but stuck in endless loop when value increased from 10 to 2...
more »

## How to fix aborting Fibonacci sequence code

I am trying to get a Fibonacci sequence of 5 million elements. This code aborts abnormally, when I pass 1000 as a parameter. def self.fibo_seq(limit) result_array = [0,1] return result_array if limit < 2 while result_array.length <= l...
more »

## How this Fibonacci code(Ruby) works?

I understood how the formula for Fibonacci works but not the recursion part. For example, fib(4) will call for fib(3) + fib(2), then what? How does the method determines the value of fib(3) and fib(2)? I am a beginner in Ruby so please excuse me for ...
more »