Hi My goal is read only line from file , and find fibonacci series that has minimun 3 element.I want to control numbers from 1 to 6 digit. Fibonacci series starts 1,1,2,3,5,8,13,21,34,55,89, ...... .For example;File text document
49693463452312343388645
I division string 1 to 6 digit. Check 4 is fibonacci number , no , go ahaed 49 is fibonacci number , no, next 496 is fibonacci ,no, 4969 after 44693 ,after 496934 no.There isnt any fibonacci , go to next digit and do it again 9 , 96,969,9693,96934.
use 5.010; use strict; use warnings; open(FILE, "<:encoding(UTF8)", "aa.txt") or die "Could not open file: + $!"; my $numbers; while (<FILE>) { $numbers="$_" ; print "$_"; } chomp $numbers; print "\n$numbers"; my $len=length($numbers); print "\n$len\n"; my $i; my $abc; foreach my $i (0..$len){ foreach my $j (1..6) { print "$j>"; $abc = substr($numbers,$i,$j); print "$abc\n"; } print "***********************************\n"; } close FILE;
I read to find fibonacci series with PERFECT SQUARE. I didn't use it. C code example
// C++ program to check if x is a perfect square #include <iostream> #include <math.h> using namespace std; // A utility function that returns true if x is perfect square bool isPerfectSquare(int x) { int s = sqrt(x); return (s*s == x); } // Returns true if n is a Fibinacci Number, else false bool isFibonacci(int n) { // n is Fibinacci if one of 5*n*n + 4 or 5*n*n  4 or both // is a perferct square return isPerfectSquare(5*n*n + 4)  isPerfectSquare(5*n*n  4); } // A utility function to test above functions int main() { for (int i = 1; i <= 10; i++) isFibonacci(i)? cout << i << " is a Fibonacci Number \n": cout << i << " is a not Fibonacci Number \n" ; + return 0; }
20171229 Athanasius restored original content


Replies are listed 'Best First'.  

Re: Read file text and find fibonacci series
by haukex (Canon) on Dec 28, 2017 at 19:12 UTC  
by vr (Chaplain) on Jan 03, 2018 at 00:01 UTC  
by haukex (Canon) on Jan 03, 2018 at 09:00 UTC  
Re: Read file text and find fibonacci series
by thanos1983 (Vicar) on Jan 02, 2018 at 18:00 UTC  
Re: Read file text and find fibonacci series
by aartist (Monk) on Jan 02, 2018 at 15:14 UTC 
Back to
Meditations