change directory names

This commit is contained in:
Pim Kunis 2023-12-04 10:25:33 +01:00
parent 3cff0fc5cf
commit 78b8881016
90 changed files with 0 additions and 0 deletions

16
18/1/2/Makefile Normal file
View file

@ -0,0 +1,16 @@
CXX = g++-7
CC = g++-7
CXXFLAGS = -Wall -Wextra
all: main
main.o: main.cpp
$(CXX) $(CXXFLAGS) -c main.cpp
main: main.o
clean:
rm -f *.o *.h.gch *.exe main
run: all
./main

998
18/1/2/input Normal file
View file

@ -0,0 +1,998 @@
-14
-9
-14
-12
+13
+2
+7
-18
+10
-8
+13
+12
+11
-1
+9
+3
+6
-1
+11
-9
-6
+11
-3
+18
-7
+13
-11
+18
+10
+9
+16
+11
+14
-19
+14
-3
-8
-5
-10
-18
-9
-10
+6
+8
+10
+10
-19
+18
+17
-14
+4
+2
+4
-17
+3
-9
-16
-16
+7
+7
+21
+13
-11
+17
+11
+1
+19
-4
+6
-7
-13
-10
+11
-4
-2
-22
-9
+8
-19
-12
-13
-8
-16
-4
-14
-8
-1
+7
+11
-4
-4
-6
-13
-12
-11
-19
-3
+10
+1
+19
+12
+9
-12
+4
+16
+14
+1
-8
-9
+5
+17
+12
-20
+7
-11
+15
+18
-10
-4
-6
+9
+19
+8
+24
-18
-10
-11
-3
+17
+17
-4
-7
-10
+20
+8
+5
+19
+31
-9
+18
-7
-13
-2
-1
+12
+1
+11
-4
+13
+3
+2
+5
+8
-1
+7
+2
+6
+9
-10
+15
+8
-6
+12
+16
+10
-19
-18
-6
+9
+1
-19
+6
-1
+5
+18
+9
+12
-6
+18
-17
+15
+5
+13
-19
+10
+14
-7
+16
-18
+8
-5
-13
+17
+17
+15
-7
-3
+18
+5
+12
+17
+11
-18
+13
+16
-14
-10
+14
+18
+2
+14
+16
+18
+9
+14
-19
+16
-12
+7
-12
-1
+4
+10
+17
-2
-3
+6
+3
+18
+10
-6
+17
-5
-13
-20
+7
+7
+9
-19
+2
+12
+8
-11
+7
-3
-8
-2
-1
-5
-15
-16
-5
-12
+2
-10
-7
-14
-2
-14
-13
-19
-17
-5
+14
-4
+5
-3
-8
+2
+2
-14
-7
+4
+16
-19
-17
-16
-18
+2
-10
+14
-16
-8
+1
-12
+4
+6
-14
-19
+11
-16
+17
+20
+8
+7
+19
+8
-18
-15
+8
-11
-24
+11
-7
-14
-18
-19
-15
-13
+22
+15
-12
-2
+19
-9
-13
-4
+10
-14
-6
+12
-11
+8
-6
-1
-5
-16
+3
-1
+21
+1
-12
+22
+30
-16
+15
-16
-7
-25
+28
+29
+10
-5
+23
+2
-12
+6
+15
+24
-4
+8
+14
-7
-13
+23
-2
+17
+4
-5
-5
-4
+6
+15
-10
+16
-1
-9
-16
-5
-10
+2
-22
+18
+10
+9
+15
-10
-19
+9
+41
+6
-4
-10
+13
+7
+6
+14
+4
+5
+19
+7
-17
-8
+7
-5
+21
-2
+12
-13
-16
+9
+11
+16
-1
+12
-15
+1
+10
-15
-20
-19
-11
+16
-9
+8
-22
+17
+18
-1
+13
+5
+23
-16
+11
-3
+18
+10
+10
-8
-6
+12
+11
+15
-19
-3
+6
-14
-10
+1
+18
-16
+8
+17
-21
-22
-5
-18
-15
-15
-5
-8
-3
-13
+5
+14
+1
+29
+12
+2
+22
+25
-34
-2
-27
+15
-23
-28
-13
+9
-26
-16
+17
-7
+35
+77
+47
-8
+34
-12
+1
-20
+24
+19
-16
+19
-14
+12
+7
+14
+13
-21
-5
-2
-5
+13
+3
+3
+2
-17
-15
+7
+12
+7
+2
-8
-12
-7
+3
-15
-16
+22
+10
-3
-10
+30
+17
-10
+11
-5
-1
+4
+15
+2
+54
-36
+53
-19
-9
-10
+50
+1
+21
+13
+14
-24
-6
-52
+11
-95
-25
-5
-14
+70
+199
-3
+2
-7
-7
+49
-7
+11
-33
-10
+13
+86
-34
-34
+127
-25
-1700
-76565
-15
+43
-9
-9
+41
+24
+24
-27
+13
-16
-19
-29
-4
-52
-25
-9
-7
+6
-19
+2
+3
+7
+19
-7
-3
+6
-16
-3
-20
+18
+16
+8
+6
-13
+18
+7
+8
-23
-1
-14
-8
-1
-8
-10
-11
-2
-5
-16
+5
+3
-17
-5
-16
-8
+7
-18
-7
-3
+13
+9
+4
+15
+19
+17
-1
-4
+14
+14
+5
-21
+11
-22
+18
+3
-13
-20
-6
-12
+4
-1
+5
+7
-19
+17
-14
+6
+6
+8
+16
+1
+8
+5
+4
+1
+22
-21
-10
-20
+15
+6
+12
+17
+9
+14
+1
-5
+10
-62
-19
-13
-1
-19
-2
-16
+4
+5
-17
-16
-3
-14
-7
+15
+5
-12
-2
+19
-13
+1
-15
-16
+12
-16
-17
+13
+12
-16
+19
+7
+1
-10
+16
-2
-8
-16
+11
-9
-12
+13
-12
+1
-11
-12
-4
+12
-9
-16
-7
+16
+12
+2
-17
-17
+9
-7
-10
-8
+1
-2
+7
+9
+8
+8
-17
-5
-7
-11
-8
-10
-6
+11
-17
-8
-13
+18
-19
+10
-19
-12
-5
-12
-15
+3
-15
+14
+9
+19
-1
-12
-10
+12
-18
-15
+4
-15
+17
-20
+10
+1
+15
+10
+10
-9
+12
-16
+15
+14
+5
-6
+3
+14
-3
+8
+2
-1
+3
-10
-7
+23
-3
-22
+5
+21
+18
-15
-9
+11
+3
+14
+11
+19
-14
-18
+14
-4
+13
+12
+12
+18
+9
-4
-18
+4
+17
-10
+20
-2
+9
-2
+4
-10
+19
-16
+4
-22
-1
+13
+7
+11
+2
+11
-19
+11
+9
+14
-9
+5
+7
+2
+13
+10
+1
+16
-5
-17
-8
+5
+4
+6
+1
+12
+14
-19
+1
+11
-8
-25
-6
-18
+26
+17
+12
-15
+19
+7
-5
+20
-5
+2
+12
-11
-6
-2
+6
-19
-24
-15
+20
+3
+26
+17
+13
-23
+31
+5
+29
-30
+5
+56
-59
-59
-40
-14
+18
-66
-7
-23
-1
-12
-6
-16
+4
+8
+17
+21
-14
-18
-7
-18
-5
+1
+12
+2
+2
+15
+21
-20
-4
-4
-14
-9
-22
+15
-9
+13
-16
+7
-17
-10
-3
-14
+2
-10
-19
-8
-19
+6
-15
-18
+3
-19
+10
-6
+7
+20
-4
-6
-13
-14
-11
+5
+7
-9
+11
-1
+9
+13
-15
-10
-13
-5
-13
-6
+5
+20
-7
-10
+13
-5
+13
-6
+5
-18
-12
-12
-17
+6
-9
-21
+1
+6
-12
+15
-14
+24
+6
+18
-16
+15
-18
-6
+20
+11
+4
-17
+8
-9
+78549

44
18/1/2/main.cpp Normal file
View file

@ -0,0 +1,44 @@
#include <map>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
map<int, bool> freqs;
ifstream input;
input.open("input");
string line;
int total = 0;
int number;
if (input.is_open()) {
while (true) {
input.clear();
input.seekg(0, ios::beg);
while (getline(input, line)) {
auto found = freqs.find(total);
if (found == freqs.end()) {
// Insert new value
freqs.insert(pair<int,bool>(total, true));
} else {
// Value was found. Exit.
cout << found->first << endl;
input.close();
return 0;
}
number = stoi(line);
total += number;
}
}
} else {
cout << "Could not open file." << endl;
}
return 1;
}

998
18/1/input Normal file
View file

@ -0,0 +1,998 @@
-14
-9
-14
-12
+13
+2
+7
-18
+10
-8
+13
+12
+11
-1
+9
+3
+6
-1
+11
-9
-6
+11
-3
+18
-7
+13
-11
+18
+10
+9
+16
+11
+14
-19
+14
-3
-8
-5
-10
-18
-9
-10
+6
+8
+10
+10
-19
+18
+17
-14
+4
+2
+4
-17
+3
-9
-16
-16
+7
+7
+21
+13
-11
+17
+11
+1
+19
-4
+6
-7
-13
-10
+11
-4
-2
-22
-9
+8
-19
-12
-13
-8
-16
-4
-14
-8
-1
+7
+11
-4
-4
-6
-13
-12
-11
-19
-3
+10
+1
+19
+12
+9
-12
+4
+16
+14
+1
-8
-9
+5
+17
+12
-20
+7
-11
+15
+18
-10
-4
-6
+9
+19
+8
+24
-18
-10
-11
-3
+17
+17
-4
-7
-10
+20
+8
+5
+19
+31
-9
+18
-7
-13
-2
-1
+12
+1
+11
-4
+13
+3
+2
+5
+8
-1
+7
+2
+6
+9
-10
+15
+8
-6
+12
+16
+10
-19
-18
-6
+9
+1
-19
+6
-1
+5
+18
+9
+12
-6
+18
-17
+15
+5
+13
-19
+10
+14
-7
+16
-18
+8
-5
-13
+17
+17
+15
-7
-3
+18
+5
+12
+17
+11
-18
+13
+16
-14
-10
+14
+18
+2
+14
+16
+18
+9
+14
-19
+16
-12
+7
-12
-1
+4
+10
+17
-2
-3
+6
+3
+18
+10
-6
+17
-5
-13
-20
+7
+7
+9
-19
+2
+12
+8
-11
+7
-3
-8
-2
-1
-5
-15
-16
-5
-12
+2
-10
-7
-14
-2
-14
-13
-19
-17
-5
+14
-4
+5
-3
-8
+2
+2
-14
-7
+4
+16
-19
-17
-16
-18
+2
-10
+14
-16
-8
+1
-12
+4
+6
-14
-19
+11
-16
+17
+20
+8
+7
+19
+8
-18
-15
+8
-11
-24
+11
-7
-14
-18
-19
-15
-13
+22
+15
-12
-2
+19
-9
-13
-4
+10
-14
-6
+12
-11
+8
-6
-1
-5
-16
+3
-1
+21
+1
-12
+22
+30
-16
+15
-16
-7
-25
+28
+29
+10
-5
+23
+2
-12
+6
+15
+24
-4
+8
+14
-7
-13
+23
-2
+17
+4
-5
-5
-4
+6
+15
-10
+16
-1
-9
-16
-5
-10
+2
-22
+18
+10
+9
+15
-10
-19
+9
+41
+6
-4
-10
+13
+7
+6
+14
+4
+5
+19
+7
-17
-8
+7
-5
+21
-2
+12
-13
-16
+9
+11
+16
-1
+12
-15
+1
+10
-15
-20
-19
-11
+16
-9
+8
-22
+17
+18
-1
+13
+5
+23
-16
+11
-3
+18
+10
+10
-8
-6
+12
+11
+15
-19
-3
+6
-14
-10
+1
+18
-16
+8
+17
-21
-22
-5
-18
-15
-15
-5
-8
-3
-13
+5
+14
+1
+29
+12
+2
+22
+25
-34
-2
-27
+15
-23
-28
-13
+9
-26
-16
+17
-7
+35
+77
+47
-8
+34
-12
+1
-20
+24
+19
-16
+19
-14
+12
+7
+14
+13
-21
-5
-2
-5
+13
+3
+3
+2
-17
-15
+7
+12
+7
+2
-8
-12
-7
+3
-15
-16
+22
+10
-3
-10
+30
+17
-10
+11
-5
-1
+4
+15
+2
+54
-36
+53
-19
-9
-10
+50
+1
+21
+13
+14
-24
-6
-52
+11
-95
-25
-5
-14
+70
+199
-3
+2
-7
-7
+49
-7
+11
-33
-10
+13
+86
-34
-34
+127
-25
-1700
-76565
-15
+43
-9
-9
+41
+24
+24
-27
+13
-16
-19
-29
-4
-52
-25
-9
-7
+6
-19
+2
+3
+7
+19
-7
-3
+6
-16
-3
-20
+18
+16
+8
+6
-13
+18
+7
+8
-23
-1
-14
-8
-1
-8
-10
-11
-2
-5
-16
+5
+3
-17
-5
-16
-8
+7
-18
-7
-3
+13
+9
+4
+15
+19
+17
-1
-4
+14
+14
+5
-21
+11
-22
+18
+3
-13
-20
-6
-12
+4
-1
+5
+7
-19
+17
-14
+6
+6
+8
+16
+1
+8
+5
+4
+1
+22
-21
-10
-20
+15
+6
+12
+17
+9
+14
+1
-5
+10
-62
-19
-13
-1
-19
-2
-16
+4
+5
-17
-16
-3
-14
-7
+15
+5
-12
-2
+19
-13
+1
-15
-16
+12
-16
-17
+13
+12
-16
+19
+7
+1
-10
+16
-2
-8
-16
+11
-9
-12
+13
-12
+1
-11
-12
-4
+12
-9
-16
-7
+16
+12
+2
-17
-17
+9
-7
-10
-8
+1
-2
+7
+9
+8
+8
-17
-5
-7
-11
-8
-10
-6
+11
-17
-8
-13
+18
-19
+10
-19
-12
-5
-12
-15
+3
-15
+14
+9
+19
-1
-12
-10
+12
-18
-15
+4
-15
+17
-20
+10
+1
+15
+10
+10
-9
+12
-16
+15
+14
+5
-6
+3
+14
-3
+8
+2
-1
+3
-10
-7
+23
-3
-22
+5
+21
+18
-15
-9
+11
+3
+14
+11
+19
-14
-18
+14
-4
+13
+12
+12
+18
+9
-4
-18
+4
+17
-10
+20
-2
+9
-2
+4
-10
+19
-16
+4
-22
-1
+13
+7
+11
+2
+11
-19
+11
+9
+14
-9
+5
+7
+2
+13
+10
+1
+16
-5
-17
-8
+5
+4
+6
+1
+12
+14
-19
+1
+11
-8
-25
-6
-18
+26
+17
+12
-15
+19
+7
-5
+20
-5
+2
+12
-11
-6
-2
+6
-19
-24
-15
+20
+3
+26
+17
+13
-23
+31
+5
+29
-30
+5
+56
-59
-59
-40
-14
+18
-66
-7
-23
-1
-12
-6
-16
+4
+8
+17
+21
-14
-18
-7
-18
-5
+1
+12
+2
+2
+15
+21
-20
-4
-4
-14
-9
-22
+15
-9
+13
-16
+7
-17
-10
-3
-14
+2
-10
-19
-8
-19
+6
-15
-18
+3
-19
+10
-6
+7
+20
-4
-6
-13
-14
-11
+5
+7
-9
+11
-1
+9
+13
-15
-10
-13
-5
-13
-6
+5
+20
-7
-10
+13
-5
+13
-6
+5
-18
-12
-12
-17
+6
-9
-21
+1
+6
-12
+15
-14
+24
+6
+18
-16
+15
-18
-6
+20
+11
+4
-17
+8
-9
+78549

36
18/1/main.c Normal file
View file

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
FILE *stream;
char *line = NULL;
size_t len = 0;
int nread;
if (argc != 2) {
fprintf(stderr, "Usage: %s <file>\n", argv[0]);
exit(EXIT_FAILURE);
}
stream = fopen(argv[1], "r");
if (stream == NULL) {
perror("fopen");
exit(EXIT_FAILURE);
}
int number;
int total = 0;
while ((nread = getline(&line, &len, stream)) != -1) {
number = atoi(line);
total += number;
}
printf("%d\n", total);
free(line);
fclose(stream);
exit(EXIT_SUCCESS);
}

16
18/2/2/Makefile Normal file
View file

@ -0,0 +1,16 @@
CXX = g++-7
CC = g++-7
CXXFLAGS = -Wall -Wextra
all: main
main.o: main.cpp
$(CXX) $(CXXFLAGS) -c main.cpp
main: main.o
clean:
rm -f *.o *.h.gch *.exe main
run: all
./main

37
18/2/2/main.cpp Normal file
View file

@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main () {
ifstream input;
input.open("../input");
string line;
vector<string> strings = {};
while (getline(input, line)) {
strings.push_back(line);
}
// Compare every string with ones that come after it.
for (vector<string>::const_iterator it = strings.begin(); it != strings.end(); ++it) {
for (vector<string>::const_iterator it2 = ++it; it2 != strings.end(); ++it2) {
int differences = 0;
string::const_iterator str_it = it->begin();
for (string::const_iterator str_it2 = it2->begin(); str_it2 != it2->end(); ++str_it2) {
if (*str_it != *str_it2) {
++differences;
}
++str_it;
}
//cout << differences << endl;
if (differences == 1) {
cout << "Found a difference of 1 in strings: " << *it << " and " << *it2 << endl;
}
}
}
}

16
18/2/Makefile Normal file
View file

@ -0,0 +1,16 @@
CXX = g++-7
CC = g++-7
CXXFLAGS = -Wall -Wextra
all: main
main.o: main.cpp
$(CXX) $(CXXFLAGS) -c main.cpp
main: main.o
clean:
rm -f *.o *.h.gch *.exe main
run: all
./main

250
18/2/input Normal file
View file

@ -0,0 +1,250 @@
bazvmqthjtrnlosiecxyghkwud
pazvmqbijirzlosiecxyghkwud
pazvtqbmjtrnlosiecxyghkwzd
pazvmqbfjtrjlosnlcxyghkwud
pazvkqbfjtrtlosiecjyghkwud
paztmqbfjtrnbosiecxyglkwud
pazvmqbfjtunlosievxmghkwud
pazvmqbfjtmngosiecyyghkwud
jazvmqbfjtrnlosiecxygikpud
pazvqqbfctrnlosimcxyghkwud
pazvmqbfjtrnwogiecxyihkwud
pazvmqbfjtrqlojiecxeghkwud
payvmqbfjtrzlosiecxyghkwuk
pkzvmqnfjtrnlosieciyghkwud
pazvmqqfjtrnldsiecxyghkwui
pazvmqbfttrqlosiecxywhkwud
gazvmybfjthnlosiecxyghkwud
pazvmqbfjtrnlasiecxygptwud
pktvmqbfjtrnwosiecxyghkwud
pazvmqwfjtrnlosiecxgghkkud
pazvmzkbjtrnlosiecxyghkwud
pazvmqbfjtrnloslecxyghuwui
pezvmqbfjtrnlesieyxyghkwud
cazvmqbfjrrnlosiecxyghkmud
pazvmqrfjjrnlosiecxyghkwnd
pazvmqbgjtrnlosiecxyphtwud
pazvmqbvmtrnlosiecxyghkpud
pazdmqbfjtrnlosiecxyuhkpud
pazvmqbflnrnloshecxyghkwud
pazvvqbfjprilosiecxyghkwud
pazvwqbfjtrllosiecxyghknud
pazvmqbfjtrnloniecxdghkaud
pazvmqbfjtrnlvsuecxynhkwud
ptzvmqwfjtrnlosieccyghkwud
pkzvmqbjjtrnlosiecryghkwud
pazvmqqfjtrexosiecxyghkwud
pazgmqbfjtrneoyiecxyghkwud
paznmqbfjtrnlosiecxydhkwzd
pazvmqbfjtrnaosiwcxsghkwud
pazomqbfjxrnlosiewxyghkwud
pazsmqbfjprnlosiecxrghkwud
pazvmqbfqtrnoosiecxygmkwud
aazvmqbfjtrnlosiacxyghjwud
pazviqbfjtrnlobiecxygrkwud
qazwmqbfjhrnlosiecxyghkwud
pazvmqbfftrnlosiqcxygfkwud
patvmqbfjtonlosircxyghkwud
pazvmqbfjtrnlomaecxyghkpud
paztmqbfjtrulossecxyghkwud
pazvmqbijtrnlobiecxyghkwkd
pazvsqbfjtrnlospecxyghkqud
pbzmmqbfjtrnlosiecxyghkwhd
pezvkqbfjtenlosiecxyghkwud
razvmqbfjkrnlosiecxeghkwud
pazcmqbfjtrnloriecxyghkgud
pazvmqbfftfnlosiecvyghkwud
pazvmqpujtrnlosiepxyghkwud
patvgqbfjtrnloslecxyghkwud
pazvmqbfltrnlosibcxyghswud
pazvmebfjtrnlosaecxyehkwud
pazdmqbejtrnlosiecxyghrwud
pazvmcbfntrplosiecxyghkwud
pszvmqbfjtrnlosivcfyghkwud
puzvmqbfjtrnloeiecxyxhkwud
pazvmqbfjtrivooiecxyghkwud
pazvyqbfjtrngosiwcxyghkwud
pauvmqbfjtrnlosimexyghkwud
pazvmqbfjtrnwoshecxeghkwud
dazvmqbfjtrnloshecxygxkwud
pazvmqbfjtrtdosiecxyghvwud
pazxmqbfjtrnlosieceyghjwud
pazvmqbfjtrnlosihexjghkwud
pazvmqbfjsrnlosiecxughiwud
phzvcqbfjtrqlosiecxyghkwud
pazvmibfjtrnlosjecxxghkwud
pazvmqbfjtrbeosiecxlghkwud
pazvmqyfjttolosiecxyghkwud
fawvmqbfjtrnlosiecxyghkwhd
pazvmqbfjprnxosiecxyghkbud
macvmqbfjtrnlosiesxyghkwud
pazsmqbfjtrflouiecxyghkwud
pacvmqbfjtrnltsiecxyghcwud
pazvmqbfjtymlosiecxygykwud
pazvmqbfjtrclosiecxygukwmd
pazvmqbfjtrnlobiecxphhkwud
mazvmqbhitrnlosiecxyghkwud
pazvmqdtjtrnlrsiecxyghkwud
pazvmqbfjgrnllsieczyghkwud
pazvmqbfjtrilosiecxxgikwud
pazvmqbjjtrnlosreceyghkwud
paxvmmbfjtrilosiecxyghkwud
pazqmwbfjtrnlowiecxyghkwud
pazvmqbfjfrnqosiecxyghkwui
pazvmqbfjtrrgosiecxyghswud
pazvmqnfjtrnlosiecsyghkwmd
paiemqbmjtrnlosiecxyghkwud
pazvmqbfdtqnlosiecxyjhkwud
pazvmxbfjthndosiecxyghkwud
pqzvmqbfjtrnlosiecxbghkzud
pagrmqbfjtrnlosiecxygskwud
pazamqtfjtrnsosiecxyghkwud
pazvmqbfjtrnldshecxyzhkwud
pazvmnbfjtrllosieclyghkwud
snzvmqbfjnrnlosiecxyghkwud
pazvsqbfjdrnlosiecxyghswud
pazvmqnfjfrnlosiecsyghkwud
pazvmqbfjtrnlosiecxjghowum
pazvmqbfjtjnlosieczygfkwud
pazvmqbsjtrnloziecxyghkeud
pazvxqbgjtrnlooiecxyghkwud
pazvmqbfjtrnlooiecxmyhkwud
pazvmqbyftrnlosgecxyghkwud
pazvmqbfjtrnlosiwcxyqhksud
pazvmqkyjtrnlokiecxyghkwud
pazfmqbfjtrnlosijcxyohkwud
pazvmqbfjtrnlociecxygikcud
fazvmqbfjtrnlosiecxyjhkuud
pazvmqbojtknlohiecxyghkwud
pazvmqbfjtgnlosbecxyghkwux
pazvmqbfjtrnlocieckoghkwud
pazvdqbfjtrlltsiecxyghkwud
pazvmqbfjtsnlfsiecxyglkwud
przvpqbfjtrnyosiecxyghkwud
pazvmbrfjtrnlosiecxmghkwud
dazvmqbfttrnlostecxyghkwud
pazvmqbfttdnlosiecxygwkwud
pazvmqbvitrnlosieexyghkwud
pazvmqbfjhrnlosjecxyvhkwud
pazvmqbfstrnlosiecxyggkwpd
bazvmqbfjtrnlmsiecxyohkwud
patmmqbfjtrnlosizcxyghkwud
pazvmqbfwtrglosieqxyghkwud
pazvmqbfjtrnlosiecxdhhkwmd
pazvmqbfjdrnlosnexxyghkwud
oazrrqbfjtrnlosiecxyghkwud
pazvmqbfjcrnlosiecxygakwjd
pazvmqbfjtrnlosifcxfghkwyd
pazvmnbfjtrnlosiecxyahzwud
pazvmqbfgtrnlojiecxyghkgud
pazvmqbfjtrnlaliecxyghkwuy
pazvmqbfjtrnlfsiecrtghkwud
pazvmqbkjtrnloswecxdghkwud
pazvtqbfjtdnlosiecxyghkwuu
pozvmqbfrtrnlosiesxyghkwud
payvmqbfjornlossecxyghkwud
pazvuqbfjtrnlosiscxyghkpud
pgzcmqbfjtrnlotiecxyghkwud
pazvvqbfjtrnlobieyxyghkwud
pazycqbfjtrnlosiecxyzhkwud
pizvdqbfjtrnlosiecxbghkwud
pazvmqbfjtrnloqiecxmgtkwud
gazvmqbfjtrnlusiecxpghkwud
pazvmqdfjtralosiecxyghkwmd
pazvmqbfjtmnlosiecxywhawud
pazvlqbfjtrnlosqecxyghqwud
pazvmqbfjtrnlhsneixyghkwud
kazvmqbfjtrqlosimcxyghkwud
pazvmwbfjtrclosiecxyghkuud
pazvmqjfjtrnlosieckyghpwud
pezvmqbgjtrnloseecxyghkwud
pazvqqbfjtfnlosvecxyghkwud
oazvmqbfjtunlosiecxyghkwad
pazvmqbfjtrncoswecxyghfwud
pazvyqbfjtrnlosqecxygtkwud
pazvmqbfjtrvlzsiecxygwkwud
pazvmqbfjjrnlosiekxylhkwud
madvmqbfjtrnlosircxyghkwud
pazvmybfjtrnlisiecxyghkwbd
pazvmqbjjixnlosiecxyghkwud
pazvmqefjtrnloqiecxyghhwud
pazveqbfjtrnlosiecgygzkwud
pazvmqbfjtrxlosiecxmgwkwud
uazvmqufjtrnlosiecxyghkwuo
pasymqbfjtrnlosiecxyghowud
pazvmqbfjtlnlpsiecxyghswud
pnzvmqbfjprnloszecxyghkwud
pafjmqcfjtrnlosiecxyghkwud
pazvmqxfbtrnloqiecxyghkwud
pazvmzbfjtrnposiccxyghkwud
pazvmqbfjotulosiecxyghkwud
pazvmqbfotrnlosgecxykhkwud
przvmqbfjtrnlosiecxyqhkwcd
pazvmqbfjtsnlogiecxyyhkwud
pazvmqbfrtrnlzsiecxyghkwug
pazvmqbfjtrnlosiecxzgukwuo
pqzvmqbqjtrnlosdecxyghkwud
pazvmqbfjtqqlosiecxughkwud
pazvmqbfjtrnlosiedhyphkwud
pazsmqbcutrnlosiecxyghkwud
pazvmqbgrtrnlosiecxyghpwud
pazemqbfjtznlosiecxyghkvud
pazvkqbfjtrilosiecxyghkwod
pfzvmqbfjtrnlopiecxygjkwud
pazvmqvfjtreloniecxyghkwud
pazvmqbfjernljsiecxgghkwud
pazvmqikjtrnlosiecxyghqwud
pazvmqbfjtrnpesoecxyghkwud
fazvmqbfjtrnlosihchyghkwud
pazvmqbfjtgnloanecxyghkwud
pazvmqsfjqrnlosiecxychkwud
parvmqbfjtrnlosiecxygfuwud
przvmqbfjtrhlosihcxyghkwud
pazvmqbcjtrnlosimcxgghkwud
pazvmqbfjtrnlosceciyjhkwud
pazvkqbfjtrylosivcxyghkwud
pazvmqbfjtrnlgsieoxyghdwud
pazvmqnfstrnlowiecxyghkwud
pazvmqbfdtrnlosieumyghkwud
pazvmqbfjtrnlosyecxfghkwul
pazvmqbfjtrclosivcxyghkcud
pazjmqbfjtrnlosiecxygokwkd
hazvmqbfjtrflosiecxzghkwud
wazvmqbfjtrnlomiecxyphkwud
yazvmqbfjirnkosiecxyghkwud
pczvmqbfjtrnlohiecxyghkwpd
pazvmqbfotrbeosiecxlghkwud
pazvmqbfjtrplosiecxynhzwud
paxvbqbwjtrnlosiecxyghkwud
pazvmqvfjtrnlosiecbyghqwud
pazjmqbfjtrnlosiecxoghkwed
pazvmqbfjtreljsitcxyghkwud
mazamqbfjtrnlosiecxoghkwud
pazvmqbfjjrnposiscxyghkwud
pbrvmqbfjtrnloliecxyghkwud
pazvmqbfjtrnlosiecxgghkyyd
pmzvmqbfntrnlosiecxyghkwuw
pazvzqbfjtrnlosienxyghzwud
pazvmqifjtvnlosrecxyghkwud
tazvmqbhjtjnlosiecxyghkwud
pazvmqbfjtlnxosiecxyghkwuo
pazvmqbfjennlosiecxyghkwxd
pahvmqbfjhrnlosiecxythkwud
pazvmlkfjtrnlxsiecxyghkwud
pfzvmqbojtrnlosieciyghkwud
pazvbqbfjtrollsiecxyghkwud
eazvmqbfjtrnlosiecayghkoud
pazvmqbfjtjnlvsiecxyghkwsd
pazvoqbojtrnlosiecfyghkwud
pazvmqbfjtuslosiecxyghksud
pazvmqbfjnrnlosiedxyghkwup
pazvmqbjjtrnlosieaxyghdwud
pazccqbfjtrhlosiecxyghkwud
pbzvmqkfjtrnlosievxyghkwud
pazvmqrljtrnlosiscxyghkwud
pazvmqbfjfoqlosiecxyghkwud
pazcmqbfjtrnlosiecxyihkwuf
pszvmqbfjtrnnosiacxyghkwud
aazvmqbfjtrnlosieyxyghkwld
pazvrqbfntrnlosiycxyghkwud
pkzvoqbfjtrnlosiecxyghxwud

48
18/2/main.cpp Normal file
View file

@ -0,0 +1,48 @@
#include <iostream>
#include <map>
#include <fstream>
using namespace std;
int main () {
int twice = 0;
int thrice = 0;
ifstream input;
input.open("input");
string line;
while (getline(input, line)) {
map<char, int> freqs;
for (string::const_iterator it = line.begin(); it != line.end(); ++it) {
auto found = freqs.find(*it);
if (found == freqs.end()) {
freqs.insert(pair<char,int>(*it, 1));
} else {
found->second++;
}
}
int twice_found = false;
int thrice_found = false;
for (map<char, int>::const_iterator it = freqs.begin(); it != freqs.end(); ++it) {
if (it->second == 2) {
twice_found = true;
} else if (it->second == 3) {
thrice_found = true;
}
}
if (twice_found) {
++twice;
}
if (thrice_found) {
++thrice;
}
}
cout << (twice * thrice) << endl;
}

1347
18/3/input Normal file

File diff suppressed because it is too large Load diff

31
18/3/main.rb Normal file
View file

@ -0,0 +1,31 @@
require 'pry'
arr = Array.new(1000){Array.new(1000){{count: 0, id: nil}}}
ids = Array.new
dups = Array.new
File.open("input", "r") do |f|
f.each_line do |line|
id = line[/\d+/].to_i
offset_left, offset_top = line[/\d+,\d+/].split(",").map(&:to_i)
width, height = line[/\d+x\d+/].split("x").map(&:to_i)
ids.push id
height.times do |y|
width.times do |x|
arr[offset_top + y][offset_left + x][:count] += 1
if arr[offset_top + y][offset_left + x][:id] != nil
dups.push arr[offset_top + y][offset_left + x][:id]
dups.push id
end
arr[offset_top + y][offset_left + x][:id] = id
end
end
end
end
puts arr.flatten.select{|a| a[:count] > 1}.count
puts (ids - dups.uniq)

1110
18/4/input Normal file

File diff suppressed because it is too large Load diff

88
18/4/main.rb Normal file
View file

@ -0,0 +1,88 @@
require 'pry'
events = []
guards = {}
File.open("input", "r") do |f|
f.each_line do |line|
events.push ({
date: line[/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/],
type: (line.end_with?("shift\n") ? :begins_shift : (line.end_with?("asleep\n") ? :falls_asleep : :wakes_up)),
id: line[/#\d+/].to_s[1..-1].to_i
})
end
end
events.sort_by! do |event|
event[:date]
end
current_guard = 0
begin_minute = 0
events.each do |event|
if event[:type] == :begins_shift
if guards[event[:id]].nil?
guards[event[:id]] = Array.new(60){0}
end
current_guard = event[:id]
elsif event[:type] == :falls_asleep
begin_minute = event[:date][-2..-1].to_i
else
(event[:date][-2..-1].to_i - begin_minute).times do |minute|
guards[current_guard][begin_minute + minute] += 1
end
end
end
# Strategy 1
sleepiest_guard = 0
longest_time = 0
guards.each do |id, counts|
time = counts.inject(:+)
if time > longest_time
longest_time = time
sleepiest_guard = id
end
end
sleepiest_minute = 0
max_count = 0
guards[sleepiest_guard].each_with_index do |count, index|
if count > max_count
max_count = count
sleepiest_minute = index
end
end
puts sleepiest_minute * sleepiest_guard
# Strategy 2
guard = 0
minute = 0
count = 0
guards.each do |id, counts|
max_count = 0
max_index = 0
counts.each_with_index do |count_, index|
if count_ > max_count
max_count = count_
max_index = index
end
end
if max_count > count
guard = id
minute = max_index
count = max_count
end
end
puts guard * minute

1
18/5/input Normal file

File diff suppressed because one or more lines are too long

49
18/5/main.rb Normal file
View file

@ -0,0 +1,49 @@
require 'pry'
input = File.open('input') {|file| file.readline}
('a'..'z').each do |letter|
output = input
temp = ""
i = 0
while i != output.length
if output[i].downcase != letter
temp += output[i]
end
i += 1
end
output = temp
temp = ""
removed = true
while removed
removed = false
i = 1
while i < output.length
if output[i - 1] != output[i] && output[i - 1].downcase == output[i].downcase
removed = true
i += 2
if i == output.length
temp += output[-1]
end
else
temp += output[i - 1]
i += 1
if i == output.length
temp += output[-1]
end
end
end
output = temp
temp = ""
end
puts "#{letter}: #{output.length}"
end

50
18/6/input Normal file
View file

@ -0,0 +1,50 @@
135, 127
251, 77
136, 244
123, 169
253, 257
359, 309
100, 247
191, 323
129, 323
76, 284
69, 56
229, 266
74, 216
236, 130
152, 126
174, 319
315, 105
329, 146
288, 51
184, 344
173, 69
293, 80
230, 270
279, 84
107, 163
130, 176
347, 114
133, 331
237, 300
291, 283
246, 297
60, 359
312, 278
242, 76
81, 356
204, 291
187, 335
176, 98
103, 274
357, 144
314, 118
67, 196
156, 265
254, 357
218, 271
118, 94
300, 189
290, 356
354, 91
209, 334

75
18/6/main.rb Normal file
View file

@ -0,0 +1,75 @@
require 'pry'
coords = []
# Parse input file.
File.open("input", "r") do |f|
f.each_line do |line|
x, y = line.split(", ").map(&:chomp).map(&:to_i)
coords.push({
x: x,
y: y,
})
end
end
# Create matrix with correct size
left_bound = right_bound = coords.first[:x]
top_bound = bottom_bound = coords.first[:y]
coords.each do |coord|
if coord[:x] < left_bound
left_bound = coord[:x]
end
if coord[:x] > right_bound
right_bound = coord[:x]
end
if coord[:y] < top_bound
top_bound = coord[:y]
end
if coord[:y] > bottom_bound
bottom_bound = coord[:y]
end
end
height = bottom_bound - top_bound + 1
width = right_bound - left_bound + 1
coords.map!{|coord| {x: coord[:x] - left_bound, y: coord[:y] - top_bound}}
matrix = Array.new(height){Array.new(width){0}}
# Fill the matrix with lowest distance to coordinates
(0...height).each do |y|
(0...width).each do |x|
coords.each_with_index do |coord, i|
distance = (x - coord[:x]).abs + (y - coord[:y]).abs
matrix[y][x] += distance
end
end
end
=begin
# Count the area for each coordinate.
(0...height).each do |y|
(0...width).each do |x|
if (y == 0 || x == 0 || y == height - 1 || x == width - 1) && matrix[y][x][:coords].length == 1
coords[matrix[y][x][:coords].first][:infinite] = true
else
if matrix[y][x][:coords].length == 1
coords[matrix[y][x][:coords].first][:area] += 1
end
end
end
end
=end
puts matrix.flatten.select{|point| point < 10000}.length

5
18/6/sample Normal file
View file

@ -0,0 +1,5 @@
0, 0
0, 10
10, 0
10, 10
3, 4

101
18/7/input Normal file
View file

@ -0,0 +1,101 @@
Step Z must be finished before step B can begin.
Step X must be finished before step D can begin.
Step D must be finished before step P can begin.
Step O must be finished before step C can begin.
Step C must be finished before step Y can begin.
Step K must be finished before step J can begin.
Step H must be finished before step T can begin.
Step B must be finished before step Q can begin.
Step V must be finished before step M can begin.
Step E must be finished before step W can begin.
Step S must be finished before step J can begin.
Step I must be finished before step N can begin.
Step T must be finished before step L can begin.
Step N must be finished before step M can begin.
Step P must be finished before step G can begin.
Step F must be finished before step Q can begin.
Step J must be finished before step G can begin.
Step L must be finished before step G can begin.
Step Y must be finished before step R can begin.
Step U must be finished before step A can begin.
Step W must be finished before step G can begin.
Step R must be finished before step G can begin.
Step G must be finished before step M can begin.
Step A must be finished before step Q can begin.
Step M must be finished before step Q can begin.
Step N must be finished before step F can begin.
Step Y must be finished before step W can begin.
Step J must be finished before step W can begin.
Step U must be finished before step G can begin.
Step X must be finished before step L can begin.
Step P must be finished before step J can begin.
Step L must be finished before step Y can begin.
Step G must be finished before step Q can begin.
Step K must be finished before step G can begin.
Step V must be finished before step J can begin.
Step F must be finished before step U can begin.
Step V must be finished before step N can begin.
Step I must be finished before step T can begin.
Step U must be finished before step W can begin.
Step S must be finished before step A can begin.
Step C must be finished before step G can begin.
Step L must be finished before step A can begin.
Step E must be finished before step L can begin.
Step D must be finished before step H can begin.
Step Z must be finished before step E can begin.
Step J must be finished before step U can begin.
Step R must be finished before step A can begin.
Step C must be finished before step J can begin.
Step T must be finished before step R can begin.
Step Z must be finished before step D can begin.
Step Y must be finished before step G can begin.
Step Y must be finished before step M can begin.
Step X must be finished before step H can begin.
Step S must be finished before step Q can begin.
Step R must be finished before step Q can begin.
Step D must be finished before step Q can begin.
Step G must be finished before step A can begin.
Step N must be finished before step A can begin.
Step F must be finished before step L can begin.
Step O must be finished before step N can begin.
Step T must be finished before step J can begin.
Step S must be finished before step T can begin.
Step O must be finished before step M can begin.
Step P must be finished before step Y can begin.
Step I must be finished before step U can begin.
Step V must be finished before step S can begin.
Step F must be finished before step G can begin.
Step P must be finished before step M can begin.
Step C must be finished before step S can begin.
Step A must be finished before step M can begin.
Step C must be finished before step Q can begin.
Step Y must be finished before step Q can begin.
Step O must be finished before step P can begin.
Step S must be finished before step R can begin.
Step S must be finished before step Y can begin.
Step I must be finished before step Q can begin.
Step O must be finished before step T can begin.
Step F must be finished before step W can begin.
Step U must be finished before step R can begin.
Step O must be finished before step U can begin.
Step D must be finished before step L can begin.
Step H must be finished before step I can begin.
Step P must be finished before step R can begin.
Step J must be finished before step L can begin.
Step P must be finished before step W can begin.
Step W must be finished before step Q can begin.
Step X must be finished before step Q can begin.
Step Z must be finished before step U can begin.
Step T must be finished before step U can begin.
Step D must be finished before step S can begin.
Step U must be finished before step Q can begin.
Step N must be finished before step G can begin.
Step E must be finished before step Q can begin.
Step X must be finished before step K can begin.
Step J must be finished before step R can begin.
Step X must be finished before step R can begin.
Step T must be finished before step W can begin.
Step K must be finished before step S can begin.
Step S must be finished before step G can begin.
Step P must be finished before step F can begin.
Step X must be finished before step C can begin.

101
18/7/main.rb Normal file
View file

@ -0,0 +1,101 @@
require 'pry'
orders = []
instructions = []
# Parse input file.
File.open("input", "r") do |f|
f.each_line do |line|
first, second = line.scan(/\s[A-Z]{1}\s/).map(&:strip)
orders.push({
first: first,
then: second
})
instructions.push(first)
instructions.push(second)
end
end
instructions.uniq!
result = ""
workers = 5.times.map do
{
current_instruction: nil,
time_left: 0
}
end
time = 0
while !instructions.empty?
# Get a list of the next instructions available.
next_instructions = instructions.select do |instruction|
orders.none? do |order|
order[:then] == instruction && order[:first] != nil
end and workers.none? do |worker|
worker[:current_instruction] == instruction
end
end.sort
# Give free workers instructions.
workers.each_with_index do |worker, i|
if worker[:current_instruction].nil? and !next_instructions.empty?
workers[i][:current_instruction] = next_instructions[0]
workers[i][:time_left] = next_instructions[0].ord - "A".ord + 1 + 60
next_instructions.delete(next_instructions[0])
end
end
elapsed_time = workers.select do |worker|
!worker[:current_instruction].nil?
end.map do |worker|
worker[:time_left]
end.min
time += elapsed_time
workers.each_with_index do |worker, i|
if !workers[i][:current_instruction].nil?
workers[i][:time_left] -= elapsed_time
if workers[i][:time_left] == 0
instructions.delete(workers[i][:current_instruction])
orders.each do |order|
if order[:first] == workers[i][:current_instruction]
order[:first] = nil
end
end
workers[i][:current_instruction] = nil
end
end
end
#binding.pry
end
=begin
while !instructions.empty?
next_instruction = instructions.select do |instruction|
orders.none? do |order|
order[:then] == instruction && order[:first] != nil
end
end.sort.first
result += next_instruction
instructions.delete next_instruction
orders.each do |order|
if order[:first] == next_instruction
order[:first] = nil
end
end
end
=end
puts time

7
18/7/sample Normal file
View file

@ -0,0 +1,7 @@
Step C must be finished before step A can begin.
Step C must be finished before step F can begin.
Step A must be finished before step B can begin.
Step A must be finished before step D can begin.
Step B must be finished before step E can begin.
Step D must be finished before step E can begin.
Step F must be finished before step E can begin.