Skip to content

Commit bfe4aee

Browse files
authored
Merge branch 'master' into circular_buffer_improvement
2 parents 8b3e29f + ac65af4 commit bfe4aee

File tree

236 files changed

+13781
-1803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+13781
-1803
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
uses: actions/setup-java@v4
1111
with:
1212
java-version: 21
13-
distribution: 'adopt'
13+
distribution: 'temurin'
1414
- name: Build with Maven
1515
run: mvn --batch-mode --update-snapshots verify
1616
- name: Upload coverage to codecov (tokenless)

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: actions/setup-java@v4
3131
with:
3232
java-version: 21
33-
distribution: 'adopt'
33+
distribution: 'temurin'
3434

3535
- name: Initialize CodeQL
3636
uses: github/codeql-action/init@v3

.github/workflows/infer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/setup-java@v4
1919
with:
2020
java-version: 21
21-
distribution: 'adopt'
21+
distribution: 'temurin'
2222

2323
- name: Set up OCaml
2424
uses: ocaml/setup-ocaml@v3

DIRECTORY.md

Lines changed: 168 additions & 14 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.junit</groupId>
2222
<artifactId>junit-bom</artifactId>
23-
<version>5.11.1</version>
23+
<version>5.11.2</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.junit.jupiter</groupId>
3333
<artifactId>junit-jupiter</artifactId>
34-
<version>5.11.1</version>
34+
<version>5.11.2</version>
3535
<scope>test</scope>
3636
</dependency>
3737
<dependency>
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>org.junit.jupiter</groupId>
4646
<artifactId>junit-jupiter-api</artifactId>
47-
<version>5.11.1</version>
47+
<version>5.11.2</version>
4848
<scope>test</scope>
4949
</dependency>
5050
<dependency>
@@ -63,7 +63,7 @@
6363
<plugins>
6464
<plugin>
6565
<artifactId>maven-surefire-plugin</artifactId>
66-
<version>3.5.0</version>
66+
<version>3.5.1</version>
6767
<configuration>
6868
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
6969
</configuration>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.thealgorithms.Recursion;
2+
3+
// program to find power set of a string
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public final class GenerateSubsets {
9+
10+
private GenerateSubsets() {
11+
throw new UnsupportedOperationException("Utility class");
12+
}
13+
14+
public static List<String> subsetRecursion(String str) {
15+
return doRecursion("", str);
16+
}
17+
18+
private static List<String> doRecursion(String p, String up) {
19+
if (up.isEmpty()) {
20+
List<String> list = new ArrayList<>();
21+
list.add(p);
22+
return list;
23+
}
24+
25+
// Taking the character
26+
char ch = up.charAt(0);
27+
// Adding the character in the recursion
28+
List<String> left = doRecursion(p + ch, up.substring(1));
29+
// Not adding the character in the recursion
30+
List<String> right = doRecursion(p, up.substring(1));
31+
32+
left.addAll(right);
33+
34+
return left;
35+
}
36+
}

src/main/java/com/thealgorithms/audiofilters/IIRFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void setCoeffs(double[] aCoeffs, double[] bCoeffs) throws IllegalArgument
5858
throw new IllegalArgumentException("bCoeffs must be of size " + order + ", got " + bCoeffs.length);
5959
}
6060

61-
for (int i = 0; i <= order; i++) {
61+
for (int i = 0; i < order; i++) {
6262
coeffsA[i] = aCoeffs[i];
6363
coeffsB[i] = bCoeffs[i];
6464
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package com.thealgorithms.backtracking;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* A class to solve a crossword puzzle using backtracking.
8+
* Example:
9+
* Input:
10+
* puzzle = {
11+
* {' ', ' ', ' '},
12+
* {' ', ' ', ' '},
13+
* {' ', ' ', ' '}
14+
* }
15+
* words = List.of("cat", "dog")
16+
*
17+
* Output:
18+
* {
19+
* {'c', 'a', 't'},
20+
* {' ', ' ', ' '},
21+
* {'d', 'o', 'g'}
22+
* }
23+
*/
24+
public final class CrosswordSolver {
25+
private CrosswordSolver() {
26+
}
27+
28+
/**
29+
* Checks if a word can be placed at the specified position in the crossword.
30+
*
31+
* @param puzzle The crossword puzzle represented as a 2D char array.
32+
* @param word The word to be placed.
33+
* @param row The row index where the word might be placed.
34+
* @param col The column index where the word might be placed.
35+
* @param vertical If true, the word is placed vertically; otherwise, horizontally.
36+
* @return true if the word can be placed, false otherwise.
37+
*/
38+
public static boolean isValid(char[][] puzzle, String word, int row, int col, boolean vertical) {
39+
for (int i = 0; i < word.length(); i++) {
40+
if (vertical) {
41+
if (row + i >= puzzle.length || puzzle[row + i][col] != ' ') {
42+
return false;
43+
}
44+
} else {
45+
if (col + i >= puzzle[0].length || puzzle[row][col + i] != ' ') {
46+
return false;
47+
}
48+
}
49+
}
50+
return true;
51+
}
52+
53+
/**
54+
* Places a word at the specified position in the crossword.
55+
*
56+
* @param puzzle The crossword puzzle represented as a 2D char array.
57+
* @param word The word to be placed.
58+
* @param row The row index where the word will be placed.
59+
* @param col The column index where the word will be placed.
60+
* @param vertical If true, the word is placed vertically; otherwise, horizontally.
61+
*/
62+
public static void placeWord(char[][] puzzle, String word, int row, int col, boolean vertical) {
63+
for (int i = 0; i < word.length(); i++) {
64+
if (vertical) {
65+
puzzle[row + i][col] = word.charAt(i);
66+
} else {
67+
puzzle[row][col + i] = word.charAt(i);
68+
}
69+
}
70+
}
71+
72+
/**
73+
* Removes a word from the specified position in the crossword.
74+
*
75+
* @param puzzle The crossword puzzle represented as a 2D char array.
76+
* @param word The word to be removed.
77+
* @param row The row index where the word is placed.
78+
* @param col The column index where the word is placed.
79+
* @param vertical If true, the word was placed vertically; otherwise, horizontally.
80+
*/
81+
public static void removeWord(char[][] puzzle, String word, int row, int col, boolean vertical) {
82+
for (int i = 0; i < word.length(); i++) {
83+
if (vertical) {
84+
puzzle[row + i][col] = ' ';
85+
} else {
86+
puzzle[row][col + i] = ' ';
87+
}
88+
}
89+
}
90+
91+
/**
92+
* Solves the crossword puzzle using backtracking.
93+
*
94+
* @param puzzle The crossword puzzle represented as a 2D char array.
95+
* @param words The list of words to be placed.
96+
* @return true if the crossword is solved, false otherwise.
97+
*/
98+
public static boolean solveCrossword(char[][] puzzle, List<String> words) {
99+
// Create a mutable copy of the words list
100+
List<String> remainingWords = new ArrayList<>(words);
101+
102+
for (int row = 0; row < puzzle.length; row++) {
103+
for (int col = 0; col < puzzle[0].length; col++) {
104+
if (puzzle[row][col] == ' ') {
105+
for (String word : new ArrayList<>(remainingWords)) {
106+
for (boolean vertical : new boolean[] {true, false}) {
107+
if (isValid(puzzle, word, row, col, vertical)) {
108+
placeWord(puzzle, word, row, col, vertical);
109+
remainingWords.remove(word);
110+
if (solveCrossword(puzzle, remainingWords)) {
111+
return true;
112+
}
113+
remainingWords.add(word);
114+
removeWord(puzzle, word, row, col, vertical);
115+
}
116+
}
117+
}
118+
return false;
119+
}
120+
}
121+
}
122+
return true;
123+
}
124+
}

0 commit comments

Comments
 (0)