-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++/armstrong-numbers: 1st iteration
- Loading branch information
Showing
12 changed files
with
319 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.PHONY: clean | ||
clean: | ||
rm -rf ./build | ||
|
||
.PHONY: test | ||
test: clean | ||
mkdir -pv ./build | ||
|
||
@printf "\n" | ||
@# each line is executed in a subshell, we have to daisy chain them so they | ||
@# run in the build directory | ||
cd ./build; export LDFLAGS="-lgcov --coverage" CXXFLAGS="--coverage"; cmake -DEXERCISM_RUN_ALL_TESTS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -G 'Unix Makefiles' ../; if make; then printf "\n=== All Tests Passed ===\n"; else printf "\n=== Test Failure ===\n"; false; fi | ||
|
||
.PHONY: coverage | ||
coverage: test | ||
@printf "\n" | ||
find . -regextype posix-egrep -regex "^.*(tests-main|CompilerId).*[.](gcda|gcno)$$" -print -delete | ||
|
||
@printf "\n" | ||
find . -regextype posix-egrep -regex "^.*[.](gcda|gcno)27066" | ||
|
||
@printf "\n" | ||
gcovr --print-summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
#include "armstrong_numbers.h" | ||
#include <cmath> | ||
|
||
namespace armstrong_numbers { | ||
|
||
} // namespace armstrong_numbers | ||
bool is_armstrong_number(int candidate) { | ||
if (candidate < 10) { | ||
return true; | ||
} | ||
|
||
const int digit_count = (int)std::log10(candidate) + 1; | ||
int num = candidate; | ||
int pow_total = 0; | ||
|
||
while (num > 0) { | ||
const int pow_temp = num % 10; | ||
int pow_temp_total = 1; | ||
|
||
for (int i = 0; i < digit_count; i++) { | ||
pow_temp_total *= pow_temp; | ||
} | ||
pow_total += pow_temp_total; | ||
num /= 10; | ||
} | ||
|
||
return pow_total == candidate; | ||
} | ||
|
||
} // namespace armstrong_numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
#if !defined(ARMSTRONG_NUMBERS_H) | ||
#define ARMSTRONG_NUMBERS_H | ||
|
||
// the C++ version is set to 17, why are you using C header files! | ||
|
||
namespace armstrong_numbers { | ||
|
||
} // namespace armstrong_numbers | ||
bool is_armstrong_number(int candidate); | ||
|
||
} // namespace armstrong_numbers | ||
|
||
#endif // ARMSTRONG_NUMBERS_H | ||
#endif // ARMSTRONG_NUMBERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>clang_version</key> | ||
<string>Debian clang version 16.0.6 (++20230610113348+7cbf1a259152-1~exp1~20230610233446.99)</string> | ||
<key>diagnostics</key> | ||
<array> | ||
</array> | ||
<key>files</key> | ||
<array> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>clang_version</key> | ||
<string>Debian clang version 16.0.6 (++20230610113348+7cbf1a259152-1~exp1~20230610233446.99)</string> | ||
<key>diagnostics</key> | ||
<array> | ||
</array> | ||
<key>files</key> | ||
<array> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"directory": "/home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/build", | ||
"command": "/usr/bin/c++ -DEXERCISM_RUN_ALL_TESTS -g -Wall -Wextra -Wpedantic -Werror -std=c++17 -o CMakeFiles/armstrong-numbers.dir/armstrong_numbers_test.cpp.o -c /home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/armstrong_numbers_test.cpp", | ||
"file": "/home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/armstrong_numbers_test.cpp" | ||
}, | ||
{ | ||
"directory": "/home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/build", | ||
"command": "/usr/bin/c++ -DEXERCISM_RUN_ALL_TESTS -g -Wall -Wextra -Wpedantic -Werror -std=c++17 -o CMakeFiles/armstrong-numbers.dir/armstrong_numbers.cpp.o -c /home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/armstrong_numbers.cpp", | ||
"file": "/home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/armstrong_numbers.cpp" | ||
}, | ||
{ | ||
"directory": "/home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/build", | ||
"command": "/usr/bin/c++ -DEXERCISM_RUN_ALL_TESTS -g -Wall -Wextra -Wpedantic -Werror -std=c++17 -o CMakeFiles/armstrong-numbers.dir/test/tests-main.cpp.o -c /home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/test/tests-main.cpp", | ||
"file": "/home/vpayno/git_vpayno/exercism-workspace/cpp/armstrong-numbers/test/tests-main.cpp" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-std=c++17 | ||
-stdlib=libstdc++ | ||
-g | ||
-Wall | ||
-Wextra | ||
-Wpedantic | ||
-Werror | ||
-Wno-unused-parameter |
Oops, something went wrong.