-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchallenge.hpp
More file actions
104 lines (75 loc) · 2.95 KB
/
challenge.hpp
File metadata and controls
104 lines (75 loc) · 2.95 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// challenge.hpp
// Challenges
//
// Created by Carlos Álvaro on 29/05/2020.
// Copyright © 2020 cdalvaro. All rights reserved.
//
#ifndef challenges_c0004_challenge_hpp
#define challenges_c0004_challenge_hpp
#include "challenges/ichallenge.hpp"
namespace challenges {
/**
@class Challenge4
@brief This class is intended to solve Challenge 4
@link https://projecteuler.net/problem=4 @endlink
*/
class Challenge4 : virtual public IChallenge {
public:
//! @copydoc IChallenge::Type_t
using Type_t = std::size_t;
/**
@brief Class constructor
This is the main constructor of Challenge4 class
@param number_of_digits The number of digits of each product number
@param number_of_products The number of products to multipy
*/
Challenge4(const std::size_t &number_of_digits, const std::size_t &number_of_products);
/**
@brief Default constructor
*/
~Challenge4() override = default;
/**
This method contains the algorithm that solves challenge 4
@return The solution for challenge 4
*/
Solution_t solve() final;
private:
std::size_t number_of_digits; ///< The number of digits of each product number
std::size_t number_of_products; ///< The number of products to multiply
/**
@brief Check if given number fulfills the required conditions
This method checks if \p number is multiple of \p number_of_factors
numbers and each divisor has \p number_of_digits digits
@param number The number to be checked
@param depth The number of products to check
@return True if the number fulfills the requirements, false otherwise.
*/
[[nodiscard]] bool checkDivisors(const Type_t &number, const std::size_t &depth) const;
/**
@brief Check wether \p number is a palindromic number or not
@param number The number to check
@return True if the number is palindromic, false otherwise
*/
static bool isPalindromic(const Type_t &number);
/**
@brief Find the next palindromic number for a given number
@param number The number to begin finding the next palindrome
@return The palindrome following the given number
*/
static Type_t findNextPalindrome(const Type_t &number);
/**
@brief Get the number of digits of a given number
@param number The number to get its number of digits
@return The number of digits for the given number
*/
static std::size_t getNumberOfDigits(const Type_t &number);
/**
@brief Flip digits for the given number
@param number The number to be flipped
@return The flipped number
*/
static Type_t flip(Type_t number);
};
} // namespace challenges
#endif /* challenges_c0004_challenge_hpp */