d1
This commit is contained in:
parent
e1b47c5f93
commit
d99a26eb06
49
aoc2017.iml
49
aoc2017.iml
@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test/resources" type="java-resource" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="module-library" exported="">
|
|
||||||
<library>
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$MODULE_DIR$/../tools/out/artifacts/tools_jar/de.domainforge.tools.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</orderEntry>
|
|
||||||
<orderEntry type="module-library">
|
|
||||||
<library name="JUnit4">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</orderEntry>
|
|
||||||
<orderEntry type="module-library">
|
|
||||||
<library name="JUnit5.7.0">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.7.0/junit-jupiter-5.7.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.7.0/junit-platform-commons-1.7.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.7.0/junit-jupiter-params-5.7.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.7.0/junit-jupiter-engine-5.7.0.jar!/" />
|
|
||||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.7.0/junit-platform-engine-1.7.0.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</orderEntry>
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
36
day01.py
Normal file
36
day01.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(1251, "input1")
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(1244, "input1")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
sum = 0
|
||||||
|
last_x = self.getInput()[-1]
|
||||||
|
for x in self.getInput():
|
||||||
|
if x == last_x:
|
||||||
|
sum += int(x)
|
||||||
|
last_x = x
|
||||||
|
return sum
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
sum = 0
|
||||||
|
x = self.getInput()
|
||||||
|
a, b = x[:len(x)//2], x[len(x)//2:]
|
||||||
|
for i, x in enumerate(a):
|
||||||
|
if x == b[i]:
|
||||||
|
sum += int(x) * 2
|
||||||
|
return sum
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(2017, 1)
|
||||||
|
day.run(verbose=True)
|
||||||
24
skel_day.py
Normal file
24
skel_day.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(None, "input%DAY%")
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(None, "input%DAY%")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(%YEAR%, %DAY%)
|
||||||
|
day.run(verbose=True)
|
||||||
@ -1,41 +0,0 @@
|
|||||||
package de.domainforge.aoc2017;
|
|
||||||
|
|
||||||
import de.domainforge.tools.AOCDay;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class Day01 extends AOCDay {
|
|
||||||
public Day01(String input) {
|
|
||||||
super(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String part1() {
|
|
||||||
byte[] input = this.input.getBytes(StandardCharsets.UTF_8);
|
|
||||||
int res = 0;
|
|
||||||
if (input[0] == input[input.length - 1]) {
|
|
||||||
res += input[0] - 48;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < input.length - 1; i++) {
|
|
||||||
if (input[i] == input[i+1]) {
|
|
||||||
res += input[i] - 48;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.valueOf(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String part2() {
|
|
||||||
byte[] input = this.input.getBytes(StandardCharsets.UTF_8);
|
|
||||||
int res = 0;
|
|
||||||
int half = input.length / 2;
|
|
||||||
|
|
||||||
for (int i = 0; i < half; i++) {
|
|
||||||
if (input[i] == input[half + i]) {
|
|
||||||
res += (input[i] - 48) * 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.valueOf(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
package de.domainforge.aoc2017;
|
|
||||||
|
|
||||||
import de.domainforge.tools.AOCDay;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Day02 extends AOCDay {
|
|
||||||
public Day02(String input) { super(input); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String part1() {
|
|
||||||
String[] input = this.getInputAsArray();
|
|
||||||
int res = 0;
|
|
||||||
for (String line : input) {
|
|
||||||
int min = Integer.MAX_VALUE;
|
|
||||||
int max = 0;
|
|
||||||
String[] items = line.strip().split("[\s\t]+");
|
|
||||||
for (String item : items) {
|
|
||||||
int value = Integer.parseInt(item);
|
|
||||||
if (value < min) {
|
|
||||||
min = value;
|
|
||||||
}
|
|
||||||
if (value > max) {
|
|
||||||
max = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res += (max - min);
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.valueOf(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String part2() {
|
|
||||||
String[] input = this.getInputAsArray();
|
|
||||||
int res = 0;
|
|
||||||
for (String line : input) {
|
|
||||||
ArrayList<Integer> items = new ArrayList<>();
|
|
||||||
for (String number : line.strip().split("[\s\t]+")) {
|
|
||||||
items.add(Integer.parseInt(number));
|
|
||||||
}
|
|
||||||
for (Integer i : items) {
|
|
||||||
for (Integer j : items) {
|
|
||||||
if (i % j == 0 && i / j != 1) {
|
|
||||||
res += i / j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return String.valueOf(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
62 1649 1731 76 51 1295 349 719 52 1984 2015 2171 981 1809 181 1715
|
|
||||||
161 99 1506 1658 84 78 533 242 1685 86 107 1548 670 960 1641 610
|
|
||||||
95 2420 2404 2293 542 2107 2198 121 109 209 2759 1373 1446 905 1837 111
|
|
||||||
552 186 751 527 696 164 114 530 558 307 252 200 481 142 205 479
|
|
||||||
581 1344 994 1413 120 112 656 1315 1249 193 1411 1280 110 103 74 1007
|
|
||||||
2536 5252 159 179 4701 1264 1400 2313 4237 161 142 4336 1061 3987 2268 4669
|
|
||||||
3270 1026 381 185 293 3520 1705 1610 3302 628 3420 524 3172 244 295 39
|
|
||||||
4142 1835 4137 3821 3730 2094 468 141 150 3982 147 4271 1741 2039 4410 179
|
|
||||||
1796 83 2039 1252 84 1641 2165 1218 1936 335 1807 2268 66 102 1977 2445
|
|
||||||
96 65 201 275 257 282 233 60 57 200 216 134 72 105 81 212
|
|
||||||
3218 5576 5616 5253 178 3317 6147 5973 2424 274 4878 234 200 4781 5372 276
|
|
||||||
4171 2436 134 3705 3831 3952 2603 115 660 125 610 152 4517 587 1554 619
|
|
||||||
2970 128 2877 1565 1001 167 254 2672 59 473 2086 181 1305 162 1663 2918
|
|
||||||
271 348 229 278 981 1785 2290 516 473 2037 737 2291 2521 1494 1121 244
|
|
||||||
2208 2236 1451 621 1937 1952 865 61 1934 49 1510 50 1767 59 194 1344
|
|
||||||
94 2312 2397 333 1192 106 2713 2351 2650 2663 703 157 89 510 1824 125
|
|
||||||
51
start_day.py
Normal file
51
start_day.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from datetime import datetime
|
||||||
|
from os.path import exists
|
||||||
|
from platform import system
|
||||||
|
from subprocess import call
|
||||||
|
from time import sleep
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
|
||||||
|
YEAR = 2017
|
||||||
|
CHARMS = {
|
||||||
|
'Linux': '/usr/local/bin/charm',
|
||||||
|
'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd'
|
||||||
|
}
|
||||||
|
|
||||||
|
arg_parser = ArgumentParser()
|
||||||
|
arg_parser.add_argument("-d", "--day", help="start a specific day (default: today)", type=int)
|
||||||
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
|
DAY = args.day or datetime.now().day
|
||||||
|
|
||||||
|
if YEAR < 2015 or not 1 <= DAY <= 25:
|
||||||
|
print("Invalid year or day for year: %d, day: %d" % (YEAR, DAY))
|
||||||
|
exit()
|
||||||
|
|
||||||
|
day_file = "day%02d.py" % DAY
|
||||||
|
if exists(day_file):
|
||||||
|
print(day_file, "already exists. Use that one!")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
with open("skel_day.py", "r") as IN:
|
||||||
|
with open(day_file, "w") as OUT:
|
||||||
|
while in_line := IN.readline():
|
||||||
|
OUT.write(in_line.replace("%YEAR%", str(YEAR)).replace("%DAY%", str(DAY)))
|
||||||
|
|
||||||
|
start = datetime(YEAR, 12, DAY, 6, 0, 0)
|
||||||
|
now = datetime.now()
|
||||||
|
if start > now:
|
||||||
|
time_wait = start - now
|
||||||
|
if time_wait.days > 0:
|
||||||
|
print("Do you really want to wait %d days?" % time_wait.days)
|
||||||
|
exit()
|
||||||
|
|
||||||
|
for x in range(time_wait.seconds, -1, -1):
|
||||||
|
print("Day starts in %02ds.\r")
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
call([CHARMS[system()], day_file])
|
||||||
|
webbrowser.open("https://adventofcode.com/%d/day/%d" % (YEAR, DAY))
|
||||||
|
call(["git", "add", day_file])
|
||||||
@ -1,41 +0,0 @@
|
|||||||
package de.domainforge.aoc2017;
|
|
||||||
|
|
||||||
import de.domainforge.tools.*;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class Day01Test {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void part1() throws IOException {
|
|
||||||
HashMap<String, String> tests = new HashMap<>();
|
|
||||||
tests.put("input01_1_1", "3");
|
|
||||||
tests.put("input01_1_2", "4");
|
|
||||||
tests.put("input01_1_3", "0");
|
|
||||||
tests.put("input01_1_4", "9");
|
|
||||||
|
|
||||||
for (String inputFileName : tests.keySet()) {
|
|
||||||
File inputFile = new File(Objects.requireNonNull(Main.class.getClassLoader().getResource(inputFileName)).getPath());
|
|
||||||
AOCDay day01 = new Day01(FileHelper.readFileToString(inputFile));
|
|
||||||
assertEquals(tests.get(inputFileName), day01.part1());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void part2() throws IOException {
|
|
||||||
HashMap<String, String> tests = new HashMap<>();
|
|
||||||
tests.put("input01_2_1", "6");
|
|
||||||
tests.put("input01_2_2", "0");
|
|
||||||
tests.put("input01_2_3", "4");
|
|
||||||
tests.put("input01_2_4", "12");
|
|
||||||
tests.put("input01_2_5", "4");
|
|
||||||
|
|
||||||
for (String inputFileName : tests.keySet()) {
|
|
||||||
File inputFile = new File(Objects.requireNonNull(Main.class.getClassLoader().getResource(inputFileName)).getPath());
|
|
||||||
AOCDay day01 = new Day01(FileHelper.readFileToString(inputFile));
|
|
||||||
assertEquals(tests.get(inputFileName), day01.part2());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
package de.domainforge.aoc2017;
|
|
||||||
|
|
||||||
import de.domainforge.tools.AOCDay;
|
|
||||||
import de.domainforge.tools.FileHelper;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class Day02Test {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void part1() throws IOException {
|
|
||||||
HashMap<String, String> tests = new HashMap<>();
|
|
||||||
tests.put("input02_1_1", "18");
|
|
||||||
|
|
||||||
for (String inputFileName : tests.keySet()) {
|
|
||||||
File inputFile = new File(Objects.requireNonNull(Main.class.getClassLoader().getResource(inputFileName)).getPath());
|
|
||||||
AOCDay day = new Day02(FileHelper.readFileToString(inputFile));
|
|
||||||
assertEquals(tests.get(inputFileName), day.part1());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void part2() throws IOException {
|
|
||||||
HashMap<String, String> tests = new HashMap<>();
|
|
||||||
tests.put("input02_2_1", "9");
|
|
||||||
|
|
||||||
for (String inputFileName : tests.keySet()) {
|
|
||||||
File inputFile = new File(Objects.requireNonNull(Main.class.getClassLoader().getResource(inputFileName)).getPath());
|
|
||||||
AOCDay day = new Day02(FileHelper.readFileToString(inputFile));
|
|
||||||
assertEquals(tests.get(inputFileName), day.part2());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
1122
|
|
||||||
@ -1 +0,0 @@
|
|||||||
1111
|
|
||||||
@ -1 +0,0 @@
|
|||||||
1234
|
|
||||||
@ -1 +0,0 @@
|
|||||||
91212129
|
|
||||||
@ -1 +0,0 @@
|
|||||||
1212
|
|
||||||
@ -1 +0,0 @@
|
|||||||
1221
|
|
||||||
@ -1 +0,0 @@
|
|||||||
123425
|
|
||||||
@ -1 +0,0 @@
|
|||||||
123123
|
|
||||||
@ -1 +0,0 @@
|
|||||||
12131415
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
5 1 9 5
|
|
||||||
7 5 3
|
|
||||||
2 4 6 8
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
5 9 2 8
|
|
||||||
9 4 7 3
|
|
||||||
3 8 6 5
|
|
||||||
Loading…
Reference in New Issue
Block a user