Compare commits
No commits in common. "eb67e67750ed51bb4ec43652b7e7730e3d936ab1" and "ad7e40f7b2426e68e66d4b3c24c7552534d15ca0" have entirely different histories.
eb67e67750
...
ad7e40f7b2
@ -1,8 +1,3 @@
|
|||||||
# project-euler
|
# project-euler
|
||||||
|
|
||||||
Several project euler problems solved in C++
|
Several project euler problems solved in C++
|
||||||
|
|
||||||
#Euler problem 1 :
|
|
||||||
|
|
||||||
<p>If we list all the natural numbers below $10$ that are multiples of $3$ or $5$, we get $3, 5, 6$ and $9$. The sum of these multiples is $23$.</p>
|
|
||||||
<p>Find the sum of all the multiples of $3$ or $5$ below $1000$.</p>
|
|
@ -2,27 +2,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
|
||||||
#include "euler_p1.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void unit_tests() {
|
|
||||||
|
|
||||||
assert(euler1(10) == 23);
|
|
||||||
|
|
||||||
std::cout << "All tests passed! continues main." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int euler_p1() {
|
|
||||||
int res = euler1(1000);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
unit_tests();
|
std::cout << "Hello World!\n";
|
||||||
|
|
||||||
std::cout << "the result for problem 1 = " << euler_p1() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
|
||||||
|
// Debug program: F5 or Debug > Start Debugging menu
|
||||||
|
|
||||||
|
// Tips for Getting Started:
|
||||||
|
// 1. Use the Solution Explorer window to add/manage files
|
||||||
|
// 2. Use the Team Explorer window to connect to source control
|
||||||
|
// 3. Use the Output window to see build output and other messages
|
||||||
|
// 4. Use the Error List window to view errors
|
||||||
|
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
|
||||||
|
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
|
||||||
|
@ -128,10 +128,6 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="euler.cpp" />
|
<ClCompile Include="euler.cpp" />
|
||||||
<ClCompile Include="euler_p1.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="euler_p1.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -18,13 +18,5 @@
|
|||||||
<ClCompile Include="euler.cpp">
|
<ClCompile Include="euler.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="euler_p1.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="euler_p1.h">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,19 +0,0 @@
|
|||||||
#include "euler_p1.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
|
|
||||||
Find the sum of all the multiples of 3 or 5 below 1000.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
int euler1(int limit) {
|
|
||||||
int result = 0;
|
|
||||||
for (size_t i = 1; i < limit; i++)
|
|
||||||
{
|
|
||||||
if (i % 3 == 0 || i % 5 == 0)
|
|
||||||
{
|
|
||||||
result += i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
/**
|
|
||||||
* @brief Solves Euler problem 1: Multiples of 3 and 5
|
|
||||||
*
|
|
||||||
* This function calculates the sum of all the multiples of 3 or 5 below a given number.
|
|
||||||
*
|
|
||||||
* @param limit The upper limit for the range to consider (should be positive).
|
|
||||||
* @return The sum of multiples of 3 or 5 below the given limit.
|
|
||||||
*
|
|
||||||
* @note This function only works with positive integer inputs.
|
|
||||||
*/
|
|
||||||
int euler1(int limit);
|
|
Loading…
x
Reference in New Issue
Block a user