Skip to content

Commit 39ce1a8

Browse files
authored
Merge branch 'master' into bug_in_ncr_modulo_p_patch
2 parents 9ae3f63 + 2fd530c commit 39ce1a8

20 files changed

+1443
-175
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @Panquesito7 @realstealthninja

.github/workflows/awesome_workflow.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ jobs:
2727
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/filename_formatter.sh
2828
chmod +x filename_formatter.sh
2929
./filename_formatter.sh . .cpp,.hpp
30-
- name: Update DIRECTORY.md
31-
run: |
32-
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
33-
python3 build_directory_md.py C-Plus-Plus . .cpp,.hpp,.h > DIRECTORY.md
34-
git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
3530
- name: Get file changes
3631
run: |
3732
git branch
@@ -94,12 +89,26 @@ jobs:
9489
name: Compile checks
9590
runs-on: ${{ matrix.os }}
9691
needs: [MainSequence]
92+
permissions:
93+
pull-requests: write
9794
strategy:
9895
matrix:
9996
os: [ubuntu-latest, windows-latest, macOS-latest]
10097
steps:
10198
- uses: actions/checkout@v3
10299
with:
103100
submodules: true
104-
- run: cmake -B ./build -S .
105-
- run: cmake --build build
101+
- run: |
102+
cmake -B ./build -S .
103+
cmake --build build
104+
- name: Label on PR fail
105+
uses: actions/github-script@v6
106+
if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
107+
with:
108+
script: |
109+
github.rest.issues.addLabels({
110+
issue_number: context.issue.number,
111+
owner: context.repo.owner,
112+
repo: context.repo.repo,
113+
labels: ['automated tests are failing']
114+
})
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Directory writer
2+
on:
3+
push:
4+
branches:
5+
- main
6+
schedule:
7+
# ┌───────────── minute (0 - 59)
8+
# │ ┌───────────── hour (0 - 23)
9+
# │ │ ┌───────────── day of the month (1 - 31)
10+
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
11+
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
12+
# │ │ │ │ │
13+
# │ │ │ │ │
14+
# │ │ │ │ │
15+
# * * * * *
16+
- cron: '0 0 * * 1'
17+
jobs:
18+
build:
19+
if: github.repository == 'TheAlgorithms/C-Plus-Plus' # We only need this to run in our repository.
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
- name: Build directory
26+
uses: TheAlgorithms/scripts/directory_md@main
27+
with:
28+
language: C-Plus-Plus
29+
working-directory: .
30+
filetypes: .cpp,.hpp,.h
31+
ignored-directories: doc/

.vscode/settings.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@
5959
"stdexcept": "cpp",
6060
"streambuf": "cpp",
6161
"typeinfo": "cpp",
62-
"valarray": "cpp"
62+
"valarray": "cpp",
63+
"bit": "cpp",
64+
"charconv": "cpp",
65+
"compare": "cpp",
66+
"concepts": "cpp",
67+
"format": "cpp",
68+
"forward_list": "cpp",
69+
"ios": "cpp",
70+
"locale": "cpp",
71+
"queue": "cpp",
72+
"stack": "cpp",
73+
"xfacet": "cpp",
74+
"xhash": "cpp",
75+
"xiosbase": "cpp",
76+
"xlocale": "cpp",
77+
"xlocbuf": "cpp",
78+
"xlocinfo": "cpp",
79+
"xlocmes": "cpp",
80+
"xlocmon": "cpp",
81+
"xlocnum": "cpp",
82+
"xloctime": "cpp",
83+
"xmemory": "cpp",
84+
"xstddef": "cpp",
85+
"xstring": "cpp",
86+
"xtr1common": "cpp",
87+
"xtree": "cpp",
88+
"xutility": "cpp",
89+
"climits": "cpp"
6390
}
6491
}

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ add_subdirectory(machine_learning)
4343
add_subdirectory(numerical_methods)
4444
add_subdirectory(graph)
4545
add_subdirectory(divide_and_conquer)
46+
add_subdirectory(games)
47+
add_subdirectory(cpu_scheduling_algorithms)
48+
add_subdirectory(physics)
4649

4750
cmake_policy(SET CMP0054 NEW)
4851
cmake_policy(SET CMP0057 NEW)

DIRECTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
* [Tree Height](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/tree_height.cpp)
121121
* [Word Break](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/word_break.cpp)
122122

123+
## Games
124+
* [Memory Game](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/games/memory_game.cpp)
125+
123126
## Geometry
124127
* [Graham Scan Algorithm](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/geometry/graham_scan_algorithm.cpp)
125128
* [Graham Scan Functions](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/geometry/graham_scan_functions.hpp)
@@ -168,6 +171,7 @@
168171
* [Md5](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/hashing/md5.cpp)
169172
* [Quadratic Probing Hash Table](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/hashing/quadratic_probing_hash_table.cpp)
170173
* [Sha1](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/hashing/sha1.cpp)
174+
* [Sha256](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/hashing/sha256.cpp)
171175

172176
## Machine Learning
173177
* [A Star Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/machine_learning/a_star_search.cpp)
@@ -289,6 +293,7 @@
289293
* [Happy Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/happy_number.cpp)
290294
* [Iterative Tree Traversals](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/iterative_tree_traversals.cpp)
291295
* [Kadanes3](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/kadanes3.cpp)
296+
* [Kelvin To Celsius](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/kelvin_to_celsius.cpp)
292297
* [Lru Cache](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/lru_cache.cpp)
293298
* [Matrix Exponentiation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/matrix_exponentiation.cpp)
294299
* [Palindrome Of Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/others/palindrome_of_number.cpp)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This repository is a collection of open-source implementation of a variety of al
2121
* The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - [C++](https://en.wikipedia.org/wiki/C%2B%2B).
2222
* Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
2323
* Each source code is atomic using [STL classes](https://en.wikipedia.org/wiki/Standard_Template_Library) and _no external libraries_ are required for their compilation and execution. Thus, the fundamentals of the algorithms can be studied in much depth.
24-
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C-Plus-Plus/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.0 respectively.
24+
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C-Plus-Plus/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS, and Ubuntu (Linux) using MSVC 19 2022, AppleClang 14.0.0, and GNU 11.3.0 respectively.
2525
* Strict adherence to [C++11](https://en.wikipedia.org/wiki/C%2B%2B11) standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
2626
* Self-checks within programs ensure correct implementations with confidence.
2727
* Modular implementations and OpenSource licensing enable the functions to be utilized conveniently in other applications.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
2+
# with full pathname. The RELATIVE flag makes it easier to extract an executable's name
3+
# automatically.
4+
5+
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
6+
foreach( testsourcefile ${APP_SOURCES} )
7+
string( REPLACE ".cpp" "" testname ${testsourcefile} ) # File type. Example: `.cpp`
8+
add_executable( ${testname} ${testsourcefile} )
9+
10+
set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX)
11+
if(OpenMP_CXX_FOUND)
12+
target_link_libraries(${testname} OpenMP::OpenMP_CXX)
13+
endif()
14+
install(TARGETS ${testname} DESTINATION "bin/cpu_scheduling_algorithms") # Folder name. Do NOT include `<>`
15+
16+
endforeach( testsourcefile ${APP_SOURCES} )

dynamic_programming/longest_palindromic_subsequence.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file
3-
* @brief Program to find the Longest Palindormic
4-
* Subsequence of a string
3+
* @brief Program to find the [Longest Palindormic
4+
* Subsequence](https://www.geeksforgeeks.org/longest-palindromic-subsequence-dp-12/) of a string
55
*
66
* @details
77
* [Palindrome](https://en.wikipedia.org/wiki/Palindrome) string sequence of
@@ -18,8 +18,15 @@
1818
#include <vector> /// for std::vector
1919

2020
/**
21-
* Function that returns the longest palindromic
21+
* @namespace
22+
* @brief Dynamic Programming algorithms
23+
*/
24+
namespace dynamic_programming {
25+
/**
26+
* @brief Function that returns the longest palindromic
2227
* subsequence of a string
28+
* @param a string whose longest palindromic subsequence is to be found
29+
* @returns longest palindromic subsequence of the string
2330
*/
2431
std::string lps(const std::string& a) {
2532
const auto b = std::string(a.rbegin(), a.rend());
@@ -70,17 +77,22 @@ std::string lps(const std::string& a) {
7077

7178
return ans;
7279
}
80+
} // namespace dynamic_programming
7381

74-
/** Test function */
75-
void test() {
76-
assert(lps("radar") == "radar");
77-
assert(lps("abbcbaa") == "abcba");
78-
assert(lps("bbbab") == "bbbb");
79-
assert(lps("") == "");
82+
/**
83+
* @brief Self-test implementations
84+
* @returns void
85+
*/
86+
static void test() {
87+
assert(dynamic_programming::lps("radar") == "radar");
88+
assert(dynamic_programming::lps("abbcbaa") == "abcba");
89+
assert(dynamic_programming::lps("bbbab") == "bbbb");
90+
assert(dynamic_programming::lps("") == "");
8091
}
8192

8293
/**
83-
* Main Function
94+
* @brief Main Function
95+
* @returns 0 on exit
8496
*/
8597
int main() {
8698
test(); // execute the tests

games/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
2+
# with full pathname. The RELATIVE flag makes it easier to extract an executable's name
3+
# automatically.
4+
5+
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
6+
foreach( testsourcefile ${APP_SOURCES} )
7+
string( REPLACE ".cpp" "" testname ${testsourcefile} ) # File type. Example: `.cpp`
8+
add_executable( ${testname} ${testsourcefile} )
9+
10+
set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX)
11+
if(OpenMP_CXX_FOUND)
12+
target_link_libraries(${testname} OpenMP::OpenMP_CXX)
13+
endif()
14+
install(TARGETS ${testname} DESTINATION "bin/games") # Folder name. Do NOT include `<>`
15+
16+
endforeach( testsourcefile ${APP_SOURCES} )

0 commit comments

Comments
 (0)