diff --git a/pom.xml b/pom.xml
index d469778..7785dae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,24 @@
5.11.4
test
+
+ junit
+ junit
+ RELEASE
+ test
+
+
+ junit
+ junit
+ RELEASE
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ test
+
diff --git a/src/main/java/BonusExercises.java b/src/main/java/BonusExercises.java
index d02a746..12d5e1f 100644
--- a/src/main/java/BonusExercises.java
+++ b/src/main/java/BonusExercises.java
@@ -20,7 +20,7 @@ public class BonusExercises {
- Each segment (between dots) must follow same hyphen rules
*/
public boolean validateEmail(String email) {
- String regex = ""; // todo
+ String regex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; // todo
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
@@ -39,7 +39,14 @@ public class BonusExercises {
If no match for a date is found in the string, return null.
*/
public String findDate(String string) {
- // todo
+ String regex = "\\b(\\d{2}/\\d{2}/\\d{4}|\\d{4}-\\d{2}-\\d{2}|\\d{4}/\\d{2}/\\d{2})\\b";
+
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(string);
+
+ if (matcher.find()) {
+ return matcher.group();
+ }
return null;
}
@@ -54,8 +61,17 @@ public class BonusExercises {
- has no white-space in it
*/
public int findValidPasswords(String string) {
- // todo
- return -1;
+ String regex = "(?= left; j--) {
+ result[index++] = matrix[bottom][j];
+ }
+ bottom--;
+ }
+
+ if (left <= right) {
+ for (int i = bottom; i >= top; i--) {
+ result[index++] = matrix[i][left];
+ }
+ left++;
+ }
+ }
+
+ return result;
}
/*
@@ -91,8 +153,32 @@ public class MainExercises
*/
public int[][] intPartitions(int n) {
- // todo
- return null;
+ if (n <= 0) return new int[0][0];
+
+ List resultList = new ArrayList<>();
+ findPartitions(n, n, new ArrayList<>(), resultList);
+
+ int[][] resultArray = new int[resultList.size()][];
+ for (int i = 0; i < resultList.size(); i++) {
+ resultArray[i] = resultList.get(i);
+ }
+ return resultArray;
+ }
+ private void findPartitions(int n, int max, List current, List resultList) {
+ if (n == 0) {
+ int[] partition = new int[current.size()];
+ for (int i = 0; i < current.size(); i++) {
+ partition[i] = current.get(i);
+ }
+ resultList.add(partition);
+ return;
+ }
+
+ for (int i = Math.min(max, n); i >= 1; i--) {
+ current.add(i);
+ findPartitions(n - i, i, current, resultList);
+ current.removeLast();
+ }
}