Skip to content

Commit 40b78f9

Browse files
committed
Solved day 5 part 1
1 parent 95f37c9 commit 40b78f9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2015'
7-
version '0.4.2'
7+
version '0.4.3'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day05/src/main/java/de/havox_design/aoc2015/day05/MainClass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class MainClass {
66
private static final Logger LOGGER = Logger.getLogger(MainClass.class.getName());
77

88
public static void main(String[] args) {
9-
LOGGER.info("Solution 1: 13");
10-
LOGGER.info("Solution 2: 23");
9+
LOGGER.info(() -> "Solution 1: " + NiceStrings.solvePart1("day05.txt"));
10+
LOGGER.info(() -> "Solution 2: " + NiceStrings.solvePart2("day05.txt"));
1111
}
1212
}

day05/src/main/java/de/havox_design/aoc2015/day05/NiceStrings.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.havox_design.aoc2015.day05;
22

33
import de.havox_design.aoc2015.utils.DataReader;
4+
import org.apache.commons.lang3.StringUtils;
45

56
import java.util.List;
67

@@ -42,15 +43,27 @@ public int solvePart2() {
4243
}
4344

4445
private int countVowels(String string) {
45-
return 0;
46+
int numberOfVowels = 0;
47+
48+
for (char vowel : "aeiou".toCharArray()) {
49+
numberOfVowels += StringUtils.countMatches(string, vowel);
50+
}
51+
52+
return numberOfVowels;
4653
}
4754

4855
private boolean containsDoubleLetter(String string) {
56+
for (int i = 0; i < string.length() - 1; i++) {
57+
if (string.charAt(i) == string.charAt(i + 1)) {
58+
return true;
59+
}
60+
}
61+
4962
return false;
5063
}
5164

5265
private boolean containsForbiddenStrings(String string) {
53-
return false;
66+
return StringUtils.containsAny(string, "ab", "cd", "pq", "xy");
5467
}
5568

5669
private List<String> readData(String fileName) {

0 commit comments

Comments
 (0)