/*
25 = 14 * 2 - 3
47 = 25 * 2 - 3
91 = 47 * 2 - 3
91 * 2 - 3 = 179
*/
#include <iostream>
#include <vector>
#include <optional>
/*
The next number in a sequence using a simple rule:
next = previous * 2 - 3
*/
std::optional<int> nextInSeries(const std::vector<int>& seq) {
if (seq.size() < 1) {
return std::nullopt; // no data → no prediction
}
int last = seq.back();
int next = last * 2 - 3; // inferred rule
return next;
}
int main() {
std::vector<int> series = {14, 25, 47, 91};
if (auto next = nextInSeries(series)) {
std::cout << "Next number is: " << *next << "\n";
} else {
std::cout << "Cannot determine next number.\n";
}
}
/*
run:
Next number is: 179
*/