-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchallenge.cpp
More file actions
30 lines (23 loc) · 728 Bytes
/
Copy pathchallenge.cpp
File metadata and controls
30 lines (23 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// challenge.cpp
// Challenges
//
// Created by Carlos Álvaro on 27/07/2020.
// Copyright © 2020 cdalvaro. All rights reserved.
//
#include <utility>
#include "challenges/c0014/challenge.hpp"
#include "tools/math/sequences/collatz.hpp"
using namespace challenges;
Challenge14::Challenge14(const Type_t &maximum_number) : maximum_number(maximum_number) {
}
IChallenge::Solution_t Challenge14::solve() {
std::pair<Type_t, std::size_t> result = {0, 0};
for (auto seed = 1u; seed <= maximum_number; ++seed) {
auto sequence = tools::math::sequences::collatz(seed);
if (sequence.size() > result.second) {
result = {seed, sequence.size()};
}
}
return result.first;
}