I have a vector with modulo fibonacci sequence
this sequence has a cycle of what I think is a random number.
If I take Fibonacci modulo 2 i get:
0, 1, 1, 0, 1, 1, 0
The problem is I dont know how to recognise the cycle.
Please help
What you have just seen is me being very very stupid, I WAS USING A CHAR FOR A START!
also I never realised but all the sequences start with 0 then 1 then another 1, I have hastily written a piece of code that asks if after a zero theres is a one and then another one
#include "stdafx.h"
#include <iostream>
#include <vector>
int main()
{
// Fib are the two fibonnacci numbers, ModFib stores Fib,
int Mod = 0;
// First check the modulo.
std::cout << "Which modulo?" << std::endl;
std::cin >> Mod;
// Fib stores the numbers and ModFib, the Modulo ones.
std::vector<unsignedlonglong> Fib = { 0, 1 };
std::vector<unsignedint> ModFib = ModFib;
// This will create the fibonnaci number.
while ((Fib[Fib.size() - 1] + Fib[Fib.size() - 2]) >= Fib[Fib.size() - 1])
Fib.push_back(Fib[Fib.size() - 1] + Fib[Fib.size() - 2]);
// Modulo every fibonnacci number
for (unsignedint Count = 0; Count < Fib.size(); Count++)
ModFib.push_back(Fib[Count] % Mod);
// This will try and find the sequence
int Check = 0;
for (unsignedint Count = 1; Count < ModFib.size() - 3; Count++) {
if (ModFib[Count] == 0) {
Check++;
if (ModFib[Count + 1] == 1) {
Check++;
if (ModFib[Count + 2] == 1) {
Check++;
if (Check == 3)
std::cout << Count << std::endl;
Count = ModFib.size();
}
else Check = 0;
}
else Check = 0;
}
else Check = 0;
}
// Clear the buffer then when someone presses enter quit.
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return 0;
}
Please tell me anything i could improve (I know I can improve that giant load of nested if's and can anyone find a way of finding the sequence with a more elegant method!