Cool
This commit is contained in:
parent
f08a53f5e5
commit
5453166f0e
48
c/2018/1/problem_01.c
Normal file
48
c/2018/1/problem_01.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
|
||||
int frequency = 0;
|
||||
int current_line = 0;
|
||||
while(fscanf(input, "%d", ¤t_line) > 0) frequency += current_line;
|
||||
|
||||
return frequency;
|
||||
}
|
||||
|
||||
int part_2(FILE *input) {
|
||||
rewind(input);
|
||||
|
||||
bool frequencies[2000000] = {0};
|
||||
int frequency = 0;
|
||||
int current_line = 0;
|
||||
bool found = false;
|
||||
while(!found) {
|
||||
while(fscanf(input, "%d", ¤t_line) > 0) {
|
||||
frequency += current_line;
|
||||
if (frequencies[frequency + 1000000]) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
frequencies[frequency + 1000000] = true;
|
||||
}
|
||||
rewind(input);
|
||||
}
|
||||
|
||||
return frequency;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/1/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
printf("Part 2: %d\n", part_2(input));
|
||||
|
||||
fclose(input);
|
||||
}
|
||||
100
c/2018/2/problem_02.c
Normal file
100
c/2018/2/problem_02.c
Normal file
@ -0,0 +1,100 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
bool has_exactly_two;
|
||||
bool has_exactly_three;
|
||||
} ChecksumResult;
|
||||
|
||||
bool is_off_by_one(const char *id1, const char *id2) {
|
||||
bool miss = false;
|
||||
while(*id1 > 0 && *id2 > 0) {
|
||||
if (*id1 != *id2) {
|
||||
if (miss) return false;
|
||||
miss = true;
|
||||
}
|
||||
id1++;
|
||||
id2++;
|
||||
}
|
||||
|
||||
return miss;
|
||||
}
|
||||
|
||||
void off_by_one_intersection(const char *id1, const char *id2, char *intersection) {
|
||||
int i = 0;
|
||||
while(*id1 > 0 && *id2 > 0) {
|
||||
if (*id1 == *id2) {
|
||||
intersection[i] = *id1;
|
||||
i++;
|
||||
}
|
||||
id1++;
|
||||
id2++;
|
||||
}
|
||||
intersection[i] = 0;
|
||||
}
|
||||
|
||||
void checksum(const char *id, ChecksumResult *result) {
|
||||
result->has_exactly_two = false;
|
||||
result->has_exactly_three = false;
|
||||
|
||||
int char_counts[26] = {0};
|
||||
while(*id > 0) {
|
||||
char_counts[*id - 'a'] ++;
|
||||
id++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if(char_counts[i] == 2) result->has_exactly_two = true;
|
||||
if(char_counts[i] == 3) result->has_exactly_three = true;
|
||||
}
|
||||
}
|
||||
|
||||
typedef char Line[27];
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
ChecksumResult result = {0};
|
||||
int twos = 0;
|
||||
int threes = 0;
|
||||
Line line_buffer;
|
||||
while(fscanf(input, "%s", line_buffer) > 0) {
|
||||
checksum(line_buffer, &result);
|
||||
if (result.has_exactly_two) twos++;
|
||||
if (result.has_exactly_three) threes++;
|
||||
}
|
||||
return twos * threes;
|
||||
}
|
||||
|
||||
void part_2(FILE *input) {
|
||||
rewind(input);
|
||||
Line lines[250] = {0};
|
||||
Line buffer;
|
||||
int line_number = 0;
|
||||
while(fscanf(input, "%s", buffer) > 0) {
|
||||
strcpy(lines[line_number++], buffer);
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(int i = 0; !found && i < 250; i++) {
|
||||
for(int j = i; !found && j < 250; j++) {
|
||||
if(is_off_by_one(lines[i], lines[j])) {
|
||||
found = true;
|
||||
off_by_one_intersection(lines[i], lines[j], buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Part 2: %s\n", buffer);
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/2/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
part_2(input); // This is a string and I don't want to malloc it
|
||||
fclose(input);
|
||||
}
|
||||
83
c/2018/3/problem_03.c
Normal file
83
c/2018/3/problem_03.c
Normal file
@ -0,0 +1,83 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
int number;
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
} Claim;
|
||||
|
||||
bool read_claim(FILE *input, Claim *claim) {
|
||||
return fscanf(input, "#%d @ %d,%d: %dx%d\n", &claim->number, &claim->x, &claim->y, &claim->w, &claim->h) > 0;
|
||||
}
|
||||
|
||||
typedef int Fabric[1000][1000];
|
||||
bool overlapped(Claim *claim, Fabric *fabric) {
|
||||
for(int x = claim->x; x < (claim->x + claim->w); x++) {
|
||||
for(int y = claim->y; y < (claim->y + claim->h); y++) {
|
||||
if ((*fabric)[x][y] > 1) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void apply_claim(const Claim *claim, Fabric *fabric) {
|
||||
for(int x = claim->x; x < (claim->x + claim->w); x++) {
|
||||
for(int y = claim->y; y < (claim->y + claim->h); y++) {
|
||||
int *col = (*fabric)[x];
|
||||
col[y]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
Fabric fabric = {0};
|
||||
|
||||
Claim claim = {0};
|
||||
while(read_claim(input, &claim)) apply_claim(&claim, &fabric);
|
||||
|
||||
int double_claimed = 0;
|
||||
for(int x = 0; x < 1000; x++) {
|
||||
for(int y = 0; y < 1000; y++) {
|
||||
if (fabric[x][y] > 1) double_claimed++;
|
||||
}
|
||||
}
|
||||
|
||||
return double_claimed;
|
||||
}
|
||||
|
||||
int part_2(FILE *input) {
|
||||
rewind(input);
|
||||
Fabric fabric = {0};
|
||||
|
||||
Claim claims[1401] = {0};
|
||||
Claim *claim = claims;
|
||||
while(read_claim(input, claim)) {
|
||||
apply_claim(claim, &fabric);
|
||||
claim++;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 1401; i++) {
|
||||
if(!overlapped(&(claims[i]), &fabric)) {
|
||||
return claims[i].number;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/3/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
printf("Part 2: %d\n", part_2(input));
|
||||
fclose(input);
|
||||
}
|
||||
210
c/2018/4/problem_04.c
Normal file
210
c/2018/4/problem_04.c
Normal file
@ -0,0 +1,210 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum {
|
||||
BEGIN_SHIFT,
|
||||
FALL_ASLEEP,
|
||||
WAKE_UP,
|
||||
} EventType;
|
||||
|
||||
typedef struct {
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
int hour;
|
||||
int minute;
|
||||
int guard_number;
|
||||
EventType type;
|
||||
} Event;
|
||||
|
||||
typedef struct {
|
||||
int number;
|
||||
int minutes_asleep;
|
||||
int asleep_at;
|
||||
int sleep_schedule[60];
|
||||
} Guard;
|
||||
|
||||
bool read_event(FILE *input, Event *event) {
|
||||
int result = fscanf(input, "[%d-%d-%d %d:%d] ", &(event->year), &(event->month), &(event->day), &(event->hour), &(event->minute));
|
||||
if (result != 5) return false;
|
||||
|
||||
char buf[80] = {0};
|
||||
fgets(buf, 79, input);
|
||||
|
||||
if(strcmp(buf, "falls asleep\n") == 0) {
|
||||
event->type = FALL_ASLEEP;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(strcmp(buf, "wakes up\n") == 0) {
|
||||
event->type = WAKE_UP;
|
||||
return true;
|
||||
}
|
||||
|
||||
strtok(buf, "#");
|
||||
event->guard_number = atoi(strtok(NULL, " "));
|
||||
event->type = BEGIN_SHIFT;
|
||||
return true;
|
||||
}
|
||||
|
||||
void print_event(Event *event) {
|
||||
printf("[%4d-%02d-%02d %02d:%02d] ", event->year, event->month, event->day, event->hour, event->minute);
|
||||
switch(event->type) {
|
||||
case BEGIN_SHIFT:
|
||||
printf("Guard #%04d begins shift\n", event->guard_number);
|
||||
break;
|
||||
case WAKE_UP:
|
||||
printf("Guard #%04d wakes up\n", event->guard_number);
|
||||
break;
|
||||
case FALL_ASLEEP:
|
||||
printf("Guard #%04d falls asleep\n", event->guard_number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int compare_events(const void *p1, const void *p2) {
|
||||
Event *ev1 = (Event*) p1;
|
||||
Event *ev2 = (Event*) p2;
|
||||
if(ev1->year != ev2->year) return ev1->year - ev2->year;
|
||||
if(ev1->month != ev2->month) return ev1->month - ev2->month;
|
||||
if(ev1->day != ev2->day) return ev1->day - ev2->day;
|
||||
if(ev1->hour != ev2->hour) return ev1->hour - ev2->hour;
|
||||
if(ev1->minute != ev2->minute) return ev1->minute - ev2->minute;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
Guard guards[10000] = {0};
|
||||
int guard_numbers[100];
|
||||
int guard_count = 0;
|
||||
|
||||
Event events[986] = {0};
|
||||
Event *event = events;
|
||||
while(read_event(input, event)){
|
||||
for(int i = -1; i < guard_count; i++) {
|
||||
if (guard_numbers[i] == event->guard_number) goto FOUND;
|
||||
}
|
||||
guard_numbers[guard_count++] = event->guard_number;
|
||||
FOUND:
|
||||
event++;
|
||||
};
|
||||
|
||||
qsort(events, 986, sizeof(Event), compare_events);
|
||||
|
||||
int current_guard;
|
||||
for(int i = 0; i < 986; i++) {
|
||||
Event event = events[i];
|
||||
switch(event.type) {
|
||||
case BEGIN_SHIFT:
|
||||
current_guard = event.guard_number;
|
||||
guards[current_guard].number = current_guard;
|
||||
break;
|
||||
case FALL_ASLEEP:
|
||||
(&event)->guard_number = current_guard;
|
||||
guards[current_guard].asleep_at = event.minute;
|
||||
break;
|
||||
case WAKE_UP:
|
||||
(&event)->guard_number = current_guard;
|
||||
guards[current_guard].minutes_asleep += event.minute - guards[current_guard].asleep_at;
|
||||
for(int i = guards[current_guard].asleep_at; i < event.minute; i++) {
|
||||
guards[current_guard].sleep_schedule[i]++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// print_event(&event);
|
||||
}
|
||||
|
||||
Guard *sleepiest_guard = &guards[guard_numbers[0]];
|
||||
for(int i = 0; i < guard_count; i++) {
|
||||
Guard g = guards[guard_numbers[i]];
|
||||
// printf("Guard %d was asleep for %d minutes\n", g.number, g.minutes_asleep);
|
||||
if (g.minutes_asleep > sleepiest_guard->minutes_asleep) sleepiest_guard = &guards[guard_numbers[i]];
|
||||
}
|
||||
// printf("Guard %d was asleep for %d minutes\n", sleepiest_guard->number, sleepiest_guard->minutes_asleep);
|
||||
|
||||
int sleepiest_minute = 0;
|
||||
for(int i = 0; i < 60; i++) {
|
||||
if(sleepiest_guard->sleep_schedule[i] > sleepiest_guard->sleep_schedule[sleepiest_minute])
|
||||
sleepiest_minute = i;
|
||||
// printf("Minute %2d: %2d\n", i, sleepiest_guard->sleep_schedule[i]);
|
||||
}
|
||||
|
||||
// printf("Sleepiest minute was %d with %d", sleepiest_minute, sleepiest_guard->sleep_schedule[sleepiest_minute]);
|
||||
|
||||
return sleepiest_minute * sleepiest_guard->number;
|
||||
}
|
||||
|
||||
int part_2(FILE *input) {
|
||||
rewind(input);
|
||||
Guard guards[10000] = {0};
|
||||
int guard_numbers[100];
|
||||
int guard_count = 0;
|
||||
|
||||
Event events[986] = {0};
|
||||
Event *event = events;
|
||||
while(read_event(input, event)){
|
||||
for(int i = -1; i < guard_count; i++) {
|
||||
if (guard_numbers[i] == event->guard_number) goto FOUND;
|
||||
}
|
||||
guard_numbers[guard_count++] = event->guard_number;
|
||||
FOUND:
|
||||
event++;
|
||||
};
|
||||
event--;
|
||||
|
||||
qsort(events, 986, sizeof(Event), compare_events);
|
||||
|
||||
int current_guard;
|
||||
for(int i = 0; i < 986; i++) {
|
||||
Event event = events[i];
|
||||
switch(event.type) {
|
||||
case BEGIN_SHIFT:
|
||||
current_guard = event.guard_number;
|
||||
guards[current_guard].number = current_guard;
|
||||
break;
|
||||
case FALL_ASLEEP:
|
||||
(&event)->guard_number = current_guard;
|
||||
guards[current_guard].asleep_at = event.minute;
|
||||
break;
|
||||
case WAKE_UP:
|
||||
(&event)->guard_number = current_guard;
|
||||
guards[current_guard].minutes_asleep += event.minute - guards[current_guard].asleep_at;
|
||||
for(int i = guards[current_guard].asleep_at; i < event.minute; i++) {
|
||||
guards[current_guard].sleep_schedule[i]++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// print_event(&event);
|
||||
}
|
||||
|
||||
Guard sleepiest_guard = guards[guard_numbers[0]];
|
||||
int sleepiest_minute = 0;
|
||||
|
||||
for(int i = 0; i < 60; i++) {
|
||||
for(int j = 0; j < guard_count; j++) {
|
||||
Guard g = guards[guard_numbers[j]];
|
||||
if (g.sleep_schedule[i] > sleepiest_guard.sleep_schedule[sleepiest_minute]) {
|
||||
sleepiest_guard = g;
|
||||
sleepiest_minute = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sleepiest_minute * sleepiest_guard.number;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/4/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
printf("Part 2: %d\n", part_2(input));
|
||||
fclose(input);
|
||||
}
|
||||
89
c/2018/5/problem_05.c
Normal file
89
c/2018/5/problem_05.c
Normal file
@ -0,0 +1,89 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
char polymer[50001];
|
||||
fread(polymer, 50000, 1, input);
|
||||
bool changed = true;
|
||||
while(changed) {
|
||||
changed = false;
|
||||
for(int i = 0; i < 50000; i++) {
|
||||
if(polymer[i] == ' ') continue;
|
||||
|
||||
for(int j = i + 1; j < 50000; j++) {
|
||||
if(polymer[j] == ' ') continue;
|
||||
|
||||
if(polymer[i] == (polymer[j] + 'a' - 'A') || polymer[i] == (polymer[j] + 'A' - 'a') ) {
|
||||
polymer[i] = ' ';
|
||||
polymer[j] = ' ';
|
||||
changed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(int i = 0; i < 50000; i++) {
|
||||
if(polymer[i] != ' ') count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int part_2(FILE *input) {
|
||||
char polymer[50001];
|
||||
int best_count = 50000;
|
||||
for(char to_remove = 'a'; to_remove <= 'z'; to_remove++) {
|
||||
rewind(input);
|
||||
fread(polymer, 50000, 1, input);
|
||||
|
||||
for(int i = 0; i < 50000; i++) {
|
||||
if(polymer[i] == to_remove || polymer[i] == to_remove - 'a' + 'A') polymer[i] = ' ';
|
||||
}
|
||||
|
||||
bool changed = true;
|
||||
while(changed) {
|
||||
changed = false;
|
||||
for(int i = 0; i < 50000; i++) {
|
||||
if(polymer[i] == ' ') continue;
|
||||
|
||||
for(int j = i + 1; j < 50000; j++) {
|
||||
if(polymer[j] == ' ') continue;
|
||||
|
||||
if(polymer[i] == (polymer[j] + 'a' - 'A') || polymer[i] == (polymer[j] + 'A' - 'a') ) {
|
||||
polymer[i] = ' ';
|
||||
polymer[j] = ' ';
|
||||
changed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(int i = 0; i < 50000; i++) {
|
||||
if(polymer[i] != ' ') count++;
|
||||
}
|
||||
|
||||
if(count < best_count) best_count = count;
|
||||
}
|
||||
|
||||
return best_count;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/5/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
printf("Part 2: %d\n", part_2(input));
|
||||
fclose(input);
|
||||
}
|
||||
83
c/2018/6/problem_06.c
Normal file
83
c/2018/6/problem_06.c
Normal file
@ -0,0 +1,83 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
int count;
|
||||
} Coordinates;
|
||||
|
||||
int hat_dist(Coordinates c1, Coordinates c2) {
|
||||
return abs(c1.x - c2.x) + abs(c1.y - c2.y);
|
||||
}
|
||||
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
Coordinates coord_list[50] = {0};
|
||||
Coordinates *coord = coord_list;
|
||||
Coordinates max = { .x = 0, .y = 0 };
|
||||
Coordinates min = { .x = 1000, .y = 1000 };
|
||||
while(fscanf(input, "%d, %d\n", &(coord->x), &(coord->y)) == 2) {
|
||||
if (coord->x > max.x) max.x = coord->x;
|
||||
if (coord->y > max.y) max.y = coord->y;
|
||||
if (coord->x < min.x) min.x = coord->x;
|
||||
if (coord->y < min.y) min.y = coord->y;
|
||||
|
||||
// printf("%d, %d\n", coord->x, coord->y);
|
||||
coord++;
|
||||
}
|
||||
|
||||
int width = max.x - min.x + 1;
|
||||
int height = max.y - min.y + 1;
|
||||
// Time to malloc ha haaaaaaa
|
||||
char *grid = malloc(width * height * sizeof(char));
|
||||
|
||||
Coordinates curr = {0};
|
||||
for(int i = 0; i < width * height; i++) {
|
||||
curr.x = i % width + min.x;
|
||||
curr.y = i / height + min.y;
|
||||
int min_dist = width + height;
|
||||
char min_coord_index = 0;
|
||||
for(int j = 0; j < 50; j++) {
|
||||
int hat = hat_dist(curr, coord_list[j]);
|
||||
if (hat == 0) {
|
||||
min_dist = hat;
|
||||
min_coord_index = -2;
|
||||
break;
|
||||
} else if (hat < min_dist){
|
||||
min_dist = hat;
|
||||
min_coord_index = j;
|
||||
} else if (hat == min_dist) {
|
||||
min_coord_index = -1;
|
||||
}
|
||||
}
|
||||
grid[i] = min_coord_index;
|
||||
if(curr.x == min.x) puts("");
|
||||
printf("%c", min_coord_index + 'A');
|
||||
}
|
||||
|
||||
puts("");
|
||||
|
||||
free(grid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int part_2(FILE *input) {
|
||||
rewind(input);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/6/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
printf("Part 2: %d\n", part_2(input));
|
||||
fclose(input);
|
||||
}
|
||||
79
c/2018/7/problem_07.c
Normal file
79
c/2018/7/problem_07.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
char name;
|
||||
bool completed;
|
||||
char requirements[50];
|
||||
char requirements_count;
|
||||
} Step;
|
||||
|
||||
typedef struct {
|
||||
Step steps[50];
|
||||
int size;
|
||||
} StepList;
|
||||
|
||||
Step *step_list_find_step(StepList *list, char key) {
|
||||
for (int i = 0; i < list->size; i++) {
|
||||
if (list->steps[i].name == key) {
|
||||
return &(list->steps[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void step_list_add_step(StepList *list, char name) {
|
||||
list->steps[list->size++].name = name;
|
||||
}
|
||||
|
||||
void step_add_requirement(Step *step, char requirement) {
|
||||
step->requirements[step->requirements_count++] = requirement;
|
||||
}
|
||||
|
||||
bool read_line(FILE *input, StepList *list) {
|
||||
char name;
|
||||
char requirement;
|
||||
bool success = fscanf(input, "Step %c must be finished before step %c can begin.\n", &name, &requirement) == 2;
|
||||
if (!success) return false;
|
||||
|
||||
Step *step = step_list_find_step(list, name);
|
||||
if (step == NULL) {
|
||||
step_list_add_step(list, name);
|
||||
step = step_list_find_step(list, name);
|
||||
}
|
||||
step_add_requirement(step, requirement);
|
||||
return true;
|
||||
}
|
||||
|
||||
int part_1(FILE *input) {
|
||||
rewind(input);
|
||||
StepList step_list = {0};
|
||||
while (read_line(input, &step_list)) {}
|
||||
for (int i = 0; i < step_list.size; i++) {
|
||||
Step step = step_list.steps[i];
|
||||
for (int j = 0; j < step.requirements_count; j++) {
|
||||
printf("Step %c must be finished before step %c can begin.\n", step.name, step.requirements[j]);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int part_2(FILE *input) {
|
||||
rewind(input);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input_file_path = "../data/2018/7/input.txt";
|
||||
FILE *input = fopen(input_file_path, "r");
|
||||
if (input == NULL) {
|
||||
printf("Can't open file %s\n", input_file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", part_1(input));
|
||||
printf("Part 2: %d\n", part_2(input));
|
||||
fclose(input);
|
||||
}
|
||||
200
c/2020/1/input.txt
Normal file
200
c/2020/1/input.txt
Normal file
@ -0,0 +1,200 @@
|
||||
1531
|
||||
1959
|
||||
1344
|
||||
1508
|
||||
1275
|
||||
1729
|
||||
1904
|
||||
1740
|
||||
1977
|
||||
1992
|
||||
1821
|
||||
1647
|
||||
1404
|
||||
1893
|
||||
1576
|
||||
1509
|
||||
1995
|
||||
1637
|
||||
1816
|
||||
1884
|
||||
1608
|
||||
1943
|
||||
1825
|
||||
1902
|
||||
1227
|
||||
1214
|
||||
1675
|
||||
1650
|
||||
1752
|
||||
1818
|
||||
862
|
||||
2006
|
||||
227
|
||||
1504
|
||||
1724
|
||||
1961
|
||||
1758
|
||||
1803
|
||||
1991
|
||||
1126
|
||||
1909
|
||||
1643
|
||||
1980
|
||||
1889
|
||||
811
|
||||
1699
|
||||
1654
|
||||
1734
|
||||
1770
|
||||
1754
|
||||
1828
|
||||
1811
|
||||
1997
|
||||
1767
|
||||
1854
|
||||
1653
|
||||
1800
|
||||
1762
|
||||
1962
|
||||
1797
|
||||
877
|
||||
1660
|
||||
1895
|
||||
1939
|
||||
1679
|
||||
1496
|
||||
1606
|
||||
1262
|
||||
1727
|
||||
2005
|
||||
1796
|
||||
1595
|
||||
1846
|
||||
1822
|
||||
1974
|
||||
1829
|
||||
1347
|
||||
1341
|
||||
1875
|
||||
1726
|
||||
1963
|
||||
1659
|
||||
337
|
||||
1826
|
||||
1777
|
||||
1523
|
||||
1979
|
||||
1805
|
||||
1987
|
||||
2009
|
||||
1993
|
||||
374
|
||||
1546
|
||||
1706
|
||||
1748
|
||||
1743
|
||||
1725
|
||||
281
|
||||
1317
|
||||
1839
|
||||
1683
|
||||
1794
|
||||
1898
|
||||
1824
|
||||
1960
|
||||
1292
|
||||
1876
|
||||
1760
|
||||
1956
|
||||
1701
|
||||
1565
|
||||
1680
|
||||
1932
|
||||
1632
|
||||
1494
|
||||
1630
|
||||
1838
|
||||
1863
|
||||
1328
|
||||
1490
|
||||
1751
|
||||
1707
|
||||
1567
|
||||
1917
|
||||
1318
|
||||
1861
|
||||
519
|
||||
1716
|
||||
1891
|
||||
1636
|
||||
1684
|
||||
1200
|
||||
1933
|
||||
1911
|
||||
1809
|
||||
1967
|
||||
1731
|
||||
1921
|
||||
1827
|
||||
1663
|
||||
1720
|
||||
1976
|
||||
1236
|
||||
1986
|
||||
1942
|
||||
1656
|
||||
1733
|
||||
1541
|
||||
1640
|
||||
1518
|
||||
1897
|
||||
1676
|
||||
1307
|
||||
1978
|
||||
1998
|
||||
1674
|
||||
1817
|
||||
1845
|
||||
1658
|
||||
1639
|
||||
1842
|
||||
1929
|
||||
1972
|
||||
2010
|
||||
1951
|
||||
858
|
||||
1928
|
||||
1562
|
||||
1787
|
||||
1916
|
||||
1561
|
||||
1694
|
||||
1944
|
||||
1922
|
||||
1882
|
||||
1691
|
||||
589
|
||||
1940
|
||||
1624
|
||||
1570
|
||||
1557
|
||||
1791
|
||||
1492
|
||||
1919
|
||||
1615
|
||||
1571
|
||||
1657
|
||||
1984
|
||||
1521
|
||||
1766
|
||||
1790
|
||||
1782
|
||||
1874
|
||||
1198
|
||||
1764
|
||||
1278
|
||||
1688
|
||||
1905
|
||||
1786
|
||||
1281
|
||||
BIN
c/2020/1/main
Executable file
BIN
c/2020/1/main
Executable file
Binary file not shown.
107
c/2020/1/main.c
Normal file
107
c/2020/1/main.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
char *example =
|
||||
"1721\n"
|
||||
"979\n"
|
||||
"366\n"
|
||||
"299\n"
|
||||
"675\n"
|
||||
"1456\n";
|
||||
|
||||
#define INPUT_NUMBER_BUFFER_LEN 5
|
||||
|
||||
#define TARGET 2020
|
||||
#define NUMBER_BUFFER_LEN TARGET + 1
|
||||
|
||||
bool isDigit(char c) {
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
long part_1() {
|
||||
bool number_buffer[NUMBER_BUFFER_LEN] = {0};
|
||||
char input_number_buffer[INPUT_NUMBER_BUFFER_LEN] = {0};
|
||||
|
||||
char *data_buffer = load_input();
|
||||
char *data = data_buffer;
|
||||
|
||||
do {
|
||||
for (int i = 0; i < INPUT_NUMBER_BUFFER_LEN; i++) {
|
||||
if (isDigit(*data)) {
|
||||
input_number_buffer[i] = *data;
|
||||
data++;
|
||||
} else {
|
||||
input_number_buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int number = atoi(input_number_buffer);
|
||||
|
||||
// Check for TARGET matches
|
||||
if (number_buffer[TARGET - number]) {
|
||||
long x = number;
|
||||
long y = TARGET - number;
|
||||
free(data_buffer);
|
||||
return x * y;
|
||||
}
|
||||
|
||||
number_buffer[number] = true;
|
||||
|
||||
data++;
|
||||
} while (*data != 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long part_2() {
|
||||
int number_buffer[NUMBER_BUFFER_LEN] = {0};
|
||||
char input_number_buffer[INPUT_NUMBER_BUFFER_LEN] = {0};
|
||||
int previously_seen_numbers[200] = {0};
|
||||
size_t previously_seen_numbers_index = 0;
|
||||
|
||||
size_t number_buffer_index = 0;
|
||||
|
||||
char *data_buffer = load_input();
|
||||
char *data = data_buffer;
|
||||
|
||||
do {
|
||||
for (int i = 0; i < INPUT_NUMBER_BUFFER_LEN; i++) {
|
||||
if (isDigit(*data)) {
|
||||
input_number_buffer[i] = *data;
|
||||
data++;
|
||||
} else {
|
||||
input_number_buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int number = atoi(input_number_buffer);
|
||||
|
||||
// Check for TARGET matches
|
||||
int x = number_buffer[TARGET - number];
|
||||
if (x > 0) {
|
||||
free(data_buffer);
|
||||
return number * x * (TARGET - number - x);
|
||||
}
|
||||
|
||||
for (int i = 0; i < previously_seen_numbers_index; i++) {
|
||||
size_t index = number + previously_seen_numbers[i];
|
||||
if (index < NUMBER_BUFFER_LEN) number_buffer[index] = number;
|
||||
}
|
||||
|
||||
previously_seen_numbers[previously_seen_numbers_index] = number;
|
||||
previously_seen_numbers_index++;
|
||||
|
||||
data++;
|
||||
} while (*data != 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
99
c/2020/10/input.txt
Normal file
99
c/2020/10/input.txt
Normal file
@ -0,0 +1,99 @@
|
||||
84
|
||||
60
|
||||
10
|
||||
23
|
||||
126
|
||||
2
|
||||
128
|
||||
63
|
||||
59
|
||||
69
|
||||
127
|
||||
73
|
||||
140
|
||||
55
|
||||
154
|
||||
133
|
||||
36
|
||||
139
|
||||
4
|
||||
70
|
||||
110
|
||||
97
|
||||
153
|
||||
105
|
||||
41
|
||||
106
|
||||
79
|
||||
145
|
||||
35
|
||||
134
|
||||
146
|
||||
148
|
||||
13
|
||||
77
|
||||
49
|
||||
107
|
||||
46
|
||||
138
|
||||
88
|
||||
152
|
||||
83
|
||||
120
|
||||
52
|
||||
114
|
||||
159
|
||||
158
|
||||
53
|
||||
76
|
||||
16
|
||||
28
|
||||
89
|
||||
25
|
||||
42
|
||||
66
|
||||
119
|
||||
3
|
||||
17
|
||||
67
|
||||
94
|
||||
99
|
||||
7
|
||||
56
|
||||
85
|
||||
122
|
||||
18
|
||||
20
|
||||
43
|
||||
160
|
||||
54
|
||||
113
|
||||
29
|
||||
130
|
||||
19
|
||||
135
|
||||
30
|
||||
80
|
||||
116
|
||||
91
|
||||
161
|
||||
115
|
||||
141
|
||||
102
|
||||
37
|
||||
157
|
||||
129
|
||||
34
|
||||
147
|
||||
142
|
||||
151
|
||||
68
|
||||
78
|
||||
24
|
||||
90
|
||||
121
|
||||
123
|
||||
33
|
||||
98
|
||||
1
|
||||
40
|
||||
BIN
c/2020/10/main
Executable file
BIN
c/2020/10/main
Executable file
Binary file not shown.
71
c/2020/10/main.c
Normal file
71
c/2020/10/main.c
Normal file
@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
#define ADAPTER_LENGTH 99
|
||||
|
||||
void int_array_quicksort(int *array, size_t length) {
|
||||
// printf("Length: %d\n", length);
|
||||
if (length < 2) return;
|
||||
|
||||
int *low = malloc((length - 1) * sizeof(int));
|
||||
size_t low_index = 0;
|
||||
|
||||
int *high = malloc((length - 1) * sizeof(int));
|
||||
size_t high_index = 0;
|
||||
|
||||
size_t pivot_index = length / 2;
|
||||
int pivot = array[pivot_index];
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
int element = array[i];
|
||||
if (element > pivot) {
|
||||
low[low_index++] = element;
|
||||
} else {
|
||||
high[high_index++] = element;
|
||||
}
|
||||
}
|
||||
// printf("low: %d\nhigh: %d\n\n", low_index, high_index);
|
||||
|
||||
if (low_index && high_index) {
|
||||
int_array_quicksort(low, low_index);
|
||||
int_array_quicksort(high, high_index);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < low_index; i++) {
|
||||
array[i] = low[i];
|
||||
}
|
||||
array[pivot_index] = pivot;
|
||||
for (size_t i = 0; i < high_index; i++) {
|
||||
array[i + low_index + 1] = high[i];
|
||||
}
|
||||
|
||||
free(low);
|
||||
free(high);
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
char *data_buffer = load_input();
|
||||
int *adapters = malloc(sizeof(int) * ADAPTER_LENGTH);
|
||||
size_t adapter_index = 0;
|
||||
char *adapter_text = strtok(data_buffer, "\n");
|
||||
do {
|
||||
adapters[adapter_index++] = atoi(adapter_text);
|
||||
} while (adapter_text = strtok(NULL, "\n"));
|
||||
|
||||
int_array_quicksort(adapters, ADAPTER_LENGTH);
|
||||
|
||||
free(data_buffer);
|
||||
free(adapters);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
return 0;
|
||||
char *data_buffer = load_input();
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
1000
c/2020/2/input.txt
Normal file
1000
c/2020/2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
c/2020/2/main
Executable file
BIN
c/2020/2/main
Executable file
Binary file not shown.
72
c/2020/2/main.c
Normal file
72
c/2020/2/main.c
Normal file
@ -0,0 +1,72 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
char password_buffer[30] = {0};
|
||||
|
||||
bool is_valid_password_part_2(const char *password_line) {
|
||||
int char_first, char_second;
|
||||
char target_char;
|
||||
|
||||
sscanf(password_line, "%d-%d %c: %s", &char_first, &char_second, &target_char, password_buffer);
|
||||
|
||||
bool result = ((password_buffer[char_first - 1] == target_char) != (password_buffer[char_second - 1] == target_char));
|
||||
|
||||
// printf("%s: %s\n", password_line, result ? "valid" : "invalid");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_valid_password_part_1(const char *password_line) {
|
||||
int char_min, char_max;
|
||||
char target_char;
|
||||
char *password = password_buffer;
|
||||
|
||||
sscanf(password_line, "%d-%d %c: %s", &char_min, &char_max, &target_char, password_buffer);
|
||||
while(*password > 0) {
|
||||
if (*password == target_char) {
|
||||
char_min--;
|
||||
char_max--;
|
||||
}
|
||||
password++;
|
||||
}
|
||||
|
||||
bool result = char_min <= 0 && char_max >= 0;
|
||||
// printf("%s: %s\n", password_line, result ? "valid" : "invalid");
|
||||
return result;
|
||||
}
|
||||
|
||||
int count_passwords(bool (*validation_function)(const char *password)) {
|
||||
char *data_buffer = load_input();
|
||||
char *data = data_buffer;
|
||||
|
||||
int valid_passwords = 0;
|
||||
int invalid_passwords = 0;
|
||||
|
||||
char *line = strtok(data, "\n");
|
||||
do {
|
||||
if (validation_function(line)) {
|
||||
valid_passwords++;
|
||||
} else {
|
||||
invalid_passwords++;
|
||||
}
|
||||
} while (line = strtok(NULL, "\n"));
|
||||
|
||||
free(data_buffer);
|
||||
return valid_passwords;
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
return count_passwords(is_valid_password_part_1);
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
return count_passwords(is_valid_password_part_2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
return 0;
|
||||
}
|
||||
323
c/2020/3/input.txt
Normal file
323
c/2020/3/input.txt
Normal file
@ -0,0 +1,323 @@
|
||||
.#..............##....#.#.####.
|
||||
##..........#.....##...........
|
||||
.......#....##...........#.#...
|
||||
.........#.#...#..........#....
|
||||
.........#..#................##
|
||||
..#...#..#..#...........#......
|
||||
...................#...##..##..
|
||||
........#.....##...#.#.#...#...
|
||||
#..#.##......#.#..#..........#.
|
||||
......#.#...#.#...#........##.#
|
||||
.....#.####........#...........
|
||||
...###..#............#.........
|
||||
.....#.......##......#...#.....
|
||||
#......##......................
|
||||
......#..............#.........
|
||||
..##...#....###.##.............
|
||||
#...#..........#.#.........#...
|
||||
...........#........#...#......
|
||||
.....##.........#......#..#....
|
||||
#..............#....#.....#....
|
||||
.#......#....#...#............#
|
||||
.####..........##..#.#.........
|
||||
....#...#......................
|
||||
....................#....#.#...
|
||||
..........###.#...............#
|
||||
.#...........#...##............
|
||||
.#.#..#.....#...#....#.......#.
|
||||
.##........#..#....#...........
|
||||
.........#.....#......###......
|
||||
..............#..#.......#.....
|
||||
........#..#.#...........#..#..
|
||||
#.........#......#.....##.#.#..
|
||||
........#.#.#....#.............
|
||||
........#........#.#.##........
|
||||
#......#.#..........#..#.......
|
||||
..#....#...##......###..#..#...
|
||||
............#..#.#.........#...
|
||||
....#.#...........#..........##
|
||||
.......#.#.#..#......#...#.....
|
||||
..#.........##.#.........#...#.
|
||||
......#....#.#....#........#.#.
|
||||
.#....###....#..............#..
|
||||
.#....#.......#....#..#.....#..
|
||||
.....#.....#...................
|
||||
..#.....#......#......#........
|
||||
......##.##...#...#...#...#.##.
|
||||
##...#....#...#..#...#...#.....
|
||||
..#.....#...#...##.##...#......
|
||||
.....#.............##...#......
|
||||
.....................#.##..#...
|
||||
#...#....#....#........#.....#.
|
||||
..#...#.........#...#..#.....#.
|
||||
#.#......#...................#.
|
||||
..#...........##...............
|
||||
..#....#........#..#...........
|
||||
...........#...................
|
||||
.............###......#....#...
|
||||
...........#...#....#..#....#..
|
||||
.....##............#.#.......#.
|
||||
.....#..#....#...#....#........
|
||||
...............##........#.#...
|
||||
.........#...#.#....#.......#..
|
||||
#..#.......#.......#...#.......
|
||||
..#...........................#
|
||||
......#.......#..#......#......
|
||||
.#.......#..................##.
|
||||
..#.........#..#.##.#....#...##
|
||||
...#..#....#...#....#.#........
|
||||
.#...#........##..#..#.......#.
|
||||
.....#........#....#....#..#...
|
||||
............#...........#......
|
||||
..###.......#..#....#......#...
|
||||
.....#...#.......#..#..........
|
||||
..#........##.#....##..........
|
||||
#....#.............#..##......#
|
||||
....#.................##.......
|
||||
...#.......#........#....##.#.#
|
||||
##..##..#.....#.....#..........
|
||||
...#...............#....#..#...
|
||||
.#...##....#....#.....#....##..
|
||||
...#.....#......#......#.......
|
||||
#.....#.......##.....#..#....##
|
||||
.....#.#...##.#......##....#.#.
|
||||
..........#....#.#...#.........
|
||||
.#..##...#.....................
|
||||
...........##..#...#....#......
|
||||
...#......#........#.......#...
|
||||
.#......#..#........#.....#..#.
|
||||
.......#........##..#.##....#..
|
||||
.##..........#..#...#.....#....
|
||||
.....##...............#.#......
|
||||
..##.....#..#......#..##.#.#...
|
||||
....#......#.##...........#....
|
||||
#.#..#.......#......#.#........
|
||||
...#.#..#....#............#..#.
|
||||
...#..........###....#....#...#
|
||||
........##...#.......#..#....#.
|
||||
..#...#.....#..#........##.....
|
||||
...#..#.##.#.#.##..............
|
||||
.......#...#.........#.....#..#
|
||||
..#.....#.#..........#..#......
|
||||
......#..........#......#.....#
|
||||
.#...........#........#......##
|
||||
..##............#......#...#..#
|
||||
#..................#...........
|
||||
#....#..#.........#........#..#
|
||||
..#.#....###..#...#...##...##..
|
||||
...#....#..#.....#.............
|
||||
.#........##.##...#....#...#...
|
||||
.........#.......##.#.....##...
|
||||
#.#.....##...#........#...#...#
|
||||
.....#.#.##...#.....#.##..#....
|
||||
........#...##...#...#.#..#..#.
|
||||
.##....#.##...#.......#........
|
||||
...#..#................#..#....
|
||||
....#.......#......#...#.##....
|
||||
#......###..#...#......#.......
|
||||
..#...#...##...........##......
|
||||
.......#...#..##....##......#..
|
||||
....#.#.............#.#...##..#
|
||||
..........#........#...#......#
|
||||
............#.#.#....###.......
|
||||
#..#...#.#.####...#..#...#.....
|
||||
.##.......#.##...#.............
|
||||
#..#...........#.#.##.......#..
|
||||
...#..#.#...#...###..#.#..#.#..
|
||||
..#...#.....#..#....#....#.....
|
||||
.........##.......#............
|
||||
.........##.##......###........
|
||||
.............#.#....#..#.....#.
|
||||
...#....#.#.......#......##....
|
||||
............#..................
|
||||
....##...#..........#...#..#...
|
||||
#..#....#.....#.......#.##.#..#
|
||||
.....#.........##.............#
|
||||
#.....#.#...#............##..##
|
||||
..............#....#.....#.....
|
||||
.#....###..#.#.....###.#..#....
|
||||
.....#....##...#....#......#...
|
||||
..........#...#....#...........
|
||||
............#....#..#.........#
|
||||
..##.....#.#...#.......#...#...
|
||||
...#...#..#......##...#.....##.
|
||||
......#.##............##.#....#
|
||||
....#......#...##.....#.....###
|
||||
.#.###...............#...#.#...
|
||||
..#....................##...#..
|
||||
.......#.....##...........#....
|
||||
#.........#....#....#....#....#
|
||||
..#.#..##.#.#..................
|
||||
.....#.......#................#
|
||||
...........#.......#........#..
|
||||
#...#.........#.#.....#.....#..
|
||||
..........#..#...........#.....
|
||||
#..#.##..##..#.#.##.........#..
|
||||
#..#..#....##..#.........#.....
|
||||
#.#.......................#.#..
|
||||
.##......#.#...#......#....#...
|
||||
..#.#................#..##.....
|
||||
.......#..................#...#
|
||||
.....#.........##.#....#.......
|
||||
#..........#..#.#..........#..#
|
||||
..#..#.....#.........#...#.....
|
||||
..............#.....#..#...#.##
|
||||
...............................
|
||||
...#............##......#.....#
|
||||
.......#..#.............#.#....
|
||||
...........#..........#........
|
||||
...#.####..#......#...#....#...
|
||||
##......#.##.....#.............
|
||||
....#.........#...#...........#
|
||||
...#........#.......#.#..#.#.#.
|
||||
..#.......#.........#....#.....
|
||||
................#.#.#.##...#..#
|
||||
#.##...#...#..#.....#.....#..#.
|
||||
...............#...........#...
|
||||
.....##.#...............##...#.
|
||||
.#..##.##......................
|
||||
.......#.........#..#..#.......
|
||||
...#......#..................#.
|
||||
...#.#..#....#....#............
|
||||
...........#...#..#....##......
|
||||
.....#...#..#.#....#....#....#.
|
||||
.......#...#...#.#.#...........
|
||||
....#......#......#...##..#....
|
||||
##...#.#.....#..#.##...........
|
||||
#.#..#.....#..#................
|
||||
...#..#.#......#.#...........##
|
||||
##....#...#.....###..#...#....#
|
||||
...#.....#.#.#......##...#...#.
|
||||
............#.......#..........
|
||||
....#..........###.......#.....
|
||||
.................##..##....#...
|
||||
...........#........##..#......
|
||||
...#.#...#.....#........#...#..
|
||||
#...#.#......#.#...........#...
|
||||
..#..........#....#..........#.
|
||||
..#................#...........
|
||||
#...#.#....#.#.......#.........
|
||||
.#...........##..#....#....#..#
|
||||
.##........#.....#...#..#....#.
|
||||
......#......#...#.............
|
||||
.......#..#...#.##....#..#.#...
|
||||
.......#......#....#....#.#.#..
|
||||
..........##.....#....##.#.....
|
||||
.........##..#...#.....#..#....
|
||||
...#....#..........#..#...#..#.
|
||||
.......#.....##.#..#.....#...#.
|
||||
#...#......#......#...#........
|
||||
#..#....#.#......#......#......
|
||||
.......#.##....................
|
||||
...##...#.....#......##......#.
|
||||
.#...................###.......
|
||||
....#........###...#........#..
|
||||
...#............#.....#..#.....
|
||||
..................#......#....#
|
||||
..##......#..##..##......#.#...
|
||||
........##....##.......#...#...
|
||||
.#.#....#.....#.....#....#....#
|
||||
...##.#.............#....##....
|
||||
.........#.....#...#......#....
|
||||
..#.....#............#....##...
|
||||
..##.....#.....##.##...........
|
||||
#....#.#.......#..#......#.....
|
||||
##.......#.....#.....####....#.
|
||||
##...#.......#...#.....#.......
|
||||
#.....#..##.##...##..#.....#..#
|
||||
..........#......#..#.#........
|
||||
..##.#......#..............#...
|
||||
.#...#..........#.......#....#.
|
||||
..#....##...#...........#....#.
|
||||
..#.........#..#......#......#.
|
||||
.##....#......#.#.........#..##
|
||||
.......#...#....##............#
|
||||
.##.................#.#........
|
||||
...#.#...#..#..#.....#.#.......
|
||||
.#.#.......#...................
|
||||
..#..#.....#......#.....##..##.
|
||||
.#........#.##......#..........
|
||||
....##...#............#.#....#.
|
||||
.......#.#..#....##.#....#....#
|
||||
......####...#..#.....#........
|
||||
..........#..#.........#.#..#.#
|
||||
..........##.........#.##......
|
||||
.##..#.#.....#.....#....#......
|
||||
............#..#...............
|
||||
.....##.........#...#...##...##
|
||||
........#.##.#...#.....#....#.#
|
||||
#......##.#.##..........##.....
|
||||
#..#..#........#.........#..#..
|
||||
...............#.#..##.........
|
||||
.#.......##.#..#....#...#....##
|
||||
.#..##.....##......#....#...#.#
|
||||
........#...#.........#.....#.#
|
||||
...........#............#...#..
|
||||
................#...........#..
|
||||
..............##........#....#.
|
||||
..........#.....##.....#..#....
|
||||
#......#....###..#..#..........
|
||||
.....#.#.....##....#.#.......#.
|
||||
...#...#...............#.#.....
|
||||
.............#.......#.........
|
||||
.....#.....#..#......#.....#...
|
||||
.........#.................#.##
|
||||
.#.....#.##..#.................
|
||||
..#......#.......#.....#...#..#
|
||||
..#..#.#.#...#.......#.##......
|
||||
..........#..#.........#.......
|
||||
.#..........#...#....#..#...##.
|
||||
.#.#.#.###.....#...#.#.#.......
|
||||
....##............#............
|
||||
.#.#.............#..#......#.#.
|
||||
.#.#..........##..#.....#..#.#.
|
||||
...........#.##..#...#.#.....#.
|
||||
...........#..#....#...........
|
||||
..#................#.#...#....#
|
||||
...............##........##....
|
||||
....#.............#........#...
|
||||
...#......#.#.#........#.......
|
||||
#..............#..##.#..##.....
|
||||
.#.#.###................##.....
|
||||
.............#..#.........#....
|
||||
.......##..#............#...#..
|
||||
...#...#...........#.....#.....
|
||||
........#......#.#.#......#..#.
|
||||
#.##.......#......#..#..#.#....
|
||||
...#........#...........#...#..
|
||||
..#...........#.........#......
|
||||
.............#....#....#.......
|
||||
....#.........#........#......#
|
||||
..#............##..#.........#.
|
||||
.#...#...#..#...#........#..#..
|
||||
...#....##..............#......
|
||||
...........#...#....#.#.##..###
|
||||
..#....#......#.........#..#...
|
||||
.......#...#...................
|
||||
.#...#.#...................#...
|
||||
.#.....##.#.......#.#.#...##..#
|
||||
.....#..#.#.........#...#..##..
|
||||
.#..#.##.#......#......#.#...#.
|
||||
......#..#....##..#....##....##
|
||||
#...#......##........##........
|
||||
.#.........###................#
|
||||
.................#..###..#.#...
|
||||
..#.#........#..#........#...#.
|
||||
#.#....#....#..#...#.#......#..
|
||||
.#.#.............###.........#.
|
||||
.....#...............##...#...#
|
||||
..............#...#........#..#
|
||||
...................#..#.......#
|
||||
#......................#.....#.
|
||||
...#.........#..##...#...#.##..
|
||||
.....#..........#.........#....
|
||||
.....#...#............#..#.....
|
||||
.............#............#....
|
||||
...#.........#.................
|
||||
#...........#.#...............#
|
||||
.....#...#.....#..#.##.......##
|
||||
...#....#.#...........#........
|
||||
.........................#.#...
|
||||
.#..#...........#.#........#...
|
||||
.............#.#.....#..#....#.
|
||||
.....#...#.###...#..#........#.
|
||||
BIN
c/2020/3/main
Executable file
BIN
c/2020/3/main
Executable file
Binary file not shown.
54
c/2020/3/main.c
Normal file
54
c/2020/3/main.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
int process_slope(int slope[]) {
|
||||
InputWithSize *input_with_size = load_input_with_size();
|
||||
char *data_buffer = input_with_size->data_buffer;
|
||||
int input_size = input_with_size -> size;
|
||||
|
||||
char *first_line = strtok(data_buffer, "\n");
|
||||
const int course_width = strlen(first_line) + 1; // Account for \n
|
||||
|
||||
int position[2] = {0, 0};
|
||||
int index = (position[0] * course_width) + position[1];
|
||||
|
||||
int trees_hit = 0;
|
||||
do {
|
||||
if (data_buffer[index] == '#') trees_hit++;
|
||||
position[0] += slope[0];
|
||||
position[1] += slope[1];
|
||||
position[1] %= (course_width - 1);
|
||||
index = (position[0] * course_width) + position[1];
|
||||
} while (index < input_size);
|
||||
|
||||
free_input_with_size(input_with_size);
|
||||
return trees_hit;
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
int slope[2] = {1, 3};
|
||||
return process_slope(slope);
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
int slopes[5][2] = {
|
||||
1, 1,
|
||||
1, 3,
|
||||
1, 5,
|
||||
1, 7,
|
||||
2, 1
|
||||
};
|
||||
int product = 1;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
product *= process_slope(slopes[i]);
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
return 0;
|
||||
}
|
||||
1159
c/2020/4/input.txt
Normal file
1159
c/2020/4/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
c/2020/4/main
Executable file
BIN
c/2020/4/main
Executable file
Binary file not shown.
225
c/2020/4/main.c
Normal file
225
c/2020/4/main.c
Normal file
@ -0,0 +1,225 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
typedef char Year[5];
|
||||
typedef char Height[6];
|
||||
typedef char HexColor[8];
|
||||
typedef char Color[4];
|
||||
typedef char PID[10];
|
||||
typedef char CID[4];
|
||||
|
||||
typedef struct Passport {
|
||||
Year byr;
|
||||
Year iyr;
|
||||
Year eyr;
|
||||
Height hgt;
|
||||
HexColor hcl;
|
||||
Color ecl;
|
||||
PID pid;
|
||||
CID cid;
|
||||
} Passport;
|
||||
|
||||
bool is_valid_passport_part_1(Passport *passport) {
|
||||
if (passport->byr[0] == '\0') return false;
|
||||
if (passport->iyr[0] == '\0') return false;
|
||||
if (passport->eyr[0] == '\0') return false;
|
||||
if (passport->hgt[0] == '\0') return false;
|
||||
if (passport->hcl[0] == '\0') return false;
|
||||
if (passport->ecl[0] == '\0') return false;
|
||||
if (passport->pid[0] == '\0') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_valid_passport_part_2(Passport *passport) {
|
||||
// byr (Birth Year) - four digits; at least 1920 and at most 2002.
|
||||
if (passport->byr[0] == '\0') return false;
|
||||
int byr = atoi(passport->byr);
|
||||
if (byr < 1920 || byr > 2002) return false;
|
||||
|
||||
// iyr (Issue Year) - four digits; at least 2010 and at most 2020.
|
||||
if (passport->iyr[0] == '\0') return false;
|
||||
int iyr = atoi(passport->iyr);
|
||||
if (iyr < 2010 || iyr > 2020) return false;
|
||||
|
||||
// eyr (Expiration Year) - four digits; at least 2020 and at most 2030.
|
||||
if (passport->eyr[0] == '\0') return false;
|
||||
int eyr = atoi(passport->eyr);
|
||||
if (eyr < 2020 || eyr > 2030) return false;
|
||||
|
||||
// hgt (Height) - a number followed by either cm or in:
|
||||
// If cm, the number must be at least 150 and at most 193.
|
||||
// If in, the number must be at least 59 and at most 76.
|
||||
if (passport->hgt[0] == '\0') return false;
|
||||
int hgt = atoi(passport->hgt);
|
||||
if (hgt >= 59 && hgt <= 76) {
|
||||
if (passport->hgt[2] != 'i' && passport->hgt[3] != 'n') return false;
|
||||
} else if (hgt >= 150 && hgt <= 193) {
|
||||
if (passport->hgt[3] != 'c' && passport->hgt[4] != 'm') return false;
|
||||
} else return false;
|
||||
|
||||
// hcl (Hair Color) - a # followed by exactly six characters 0-9 or a-f.
|
||||
if (passport->hcl[0] != '#') return false;
|
||||
for (int i = 1; i < 7; i++) {
|
||||
char c = passport->hcl[i];
|
||||
if (c < 48 || (c > 57 && c < 97) || c > 122) return false;
|
||||
}
|
||||
|
||||
// ecl (Eye Color) - exactly one of: amb blu brn gry grn hzl oth.
|
||||
if (passport->ecl[0] == '\0') return false;
|
||||
char *ecl = passport->ecl;
|
||||
if (
|
||||
strcmp(ecl, "amb") != 0 &&
|
||||
strcmp(ecl, "blu") != 0 &&
|
||||
strcmp(ecl, "brn") != 0 &&
|
||||
strcmp(ecl, "gry") != 0 &&
|
||||
strcmp(ecl, "grn") != 0 &&
|
||||
strcmp(ecl, "hzl") != 0 &&
|
||||
strcmp(ecl, "oth") != 0 &&
|
||||
strcmp(ecl, "amb") != 0
|
||||
) return false;
|
||||
|
||||
// pid (Passport ID) - a nine-digit number, including leading zeroes.
|
||||
if (passport->pid[0] == '\0') return false;
|
||||
if (strlen(passport->pid) != 9) return false;
|
||||
|
||||
// cid (Country ID) - ignored, missing or not.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void clear_passport(Passport *passport) {
|
||||
*(passport->byr) = 0;
|
||||
*(passport->iyr) = 0;
|
||||
*(passport->eyr) = 0;
|
||||
*(passport->hgt) = 0;
|
||||
*(passport->hcl) = 0;
|
||||
*(passport->ecl) = 0;
|
||||
*(passport->pid) = 0;
|
||||
*(passport->cid) = 0;
|
||||
}
|
||||
|
||||
void print_passport(Passport *passport) {
|
||||
printf(
|
||||
"Birth Year: %s\n"
|
||||
"Issue Year: %s\n"
|
||||
"Expiration Year: %s\n"
|
||||
"Height: %s\n"
|
||||
"Hair Color: %s\n"
|
||||
"Eye Color: %s\n"
|
||||
"Passport ID: %s\n"
|
||||
"Country ID: %s\n",
|
||||
passport->byr,
|
||||
passport->iyr,
|
||||
passport->eyr,
|
||||
passport->hgt,
|
||||
passport->hcl,
|
||||
passport->ecl,
|
||||
passport->pid,
|
||||
passport->cid
|
||||
);
|
||||
}
|
||||
|
||||
void parse_passport_field(char *field, Passport *passport) {
|
||||
switch(*field) {
|
||||
case 'b':
|
||||
strcpy(passport->byr, field + 4);
|
||||
break;
|
||||
case 'i':
|
||||
strcpy(passport->iyr, field + 4);
|
||||
break;
|
||||
case 'e':
|
||||
switch(*(field + 1)) {
|
||||
case 'y':
|
||||
strcpy(passport->eyr, field + 4);
|
||||
break;
|
||||
case 'c':
|
||||
strcpy(passport->ecl, field + 4);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
switch(*(field + 1)) {
|
||||
case 'c':
|
||||
strcpy(passport->hcl, field + 4);
|
||||
break;
|
||||
case 'g':
|
||||
strcpy(passport->hgt, field + 4);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
strcpy(passport->pid, field + 4);
|
||||
break;
|
||||
case 'c':
|
||||
strcpy(passport->cid, field + 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void parse_passport(char *text, Passport *passport) {
|
||||
char *pp_text = strtok(text, " ");
|
||||
do {
|
||||
parse_passport_field(pp_text, passport);
|
||||
} while(pp_text = strtok(NULL, " "));
|
||||
}
|
||||
|
||||
int check_valid_passports(bool (*passport_validator) (Passport *passport)) {
|
||||
InputWithSize *input_with_size = load_input_with_size();
|
||||
char *input_normalized = malloc(input_with_size -> size);
|
||||
|
||||
char *data_pointer = input_with_size -> data_buffer;
|
||||
char *normalized_pointer = input_normalized;
|
||||
|
||||
int passport_count = 0;
|
||||
for (int i = 0; i < input_with_size -> size; i++) {
|
||||
if (data_pointer[i] == '\n') {
|
||||
if (data_pointer[i + 1] == '\n') {
|
||||
*normalized_pointer = '\0';
|
||||
i++;
|
||||
passport_count++;
|
||||
} else {
|
||||
*normalized_pointer = ' ';
|
||||
}
|
||||
} else {
|
||||
*normalized_pointer = data_pointer[i];
|
||||
}
|
||||
normalized_pointer++;
|
||||
}
|
||||
*normalized_pointer = 0;
|
||||
int normalized_size = normalized_pointer - input_normalized;
|
||||
free_input_with_size(input_with_size);
|
||||
|
||||
normalized_pointer = input_normalized;
|
||||
Passport *passport = malloc(sizeof(Passport));
|
||||
int passport_text_len = strlen(normalized_pointer);
|
||||
|
||||
int valid_passports = 0;
|
||||
while(*normalized_pointer != '\0') {
|
||||
clear_passport(passport);
|
||||
parse_passport(normalized_pointer, passport);
|
||||
if (passport_validator(passport)) valid_passports++;
|
||||
// print_passport(passport);
|
||||
// puts("");
|
||||
normalized_pointer += passport_text_len + 1;
|
||||
passport_text_len = strlen(normalized_pointer);
|
||||
}
|
||||
|
||||
free(passport);
|
||||
free(input_normalized);
|
||||
return valid_passports;
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
return check_valid_passports(is_valid_passport_part_1);
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
return check_valid_passports(is_valid_passport_part_2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
814
c/2020/5/input.txt
Normal file
814
c/2020/5/input.txt
Normal file
@ -0,0 +1,814 @@
|
||||
FBFBBBFRLL
|
||||
BFFFBFFRRR
|
||||
BBFBFFFLLR
|
||||
FBFFFBFLRR
|
||||
FBFFBFBLLR
|
||||
BFBBFBBRLL
|
||||
BFFFFFFRLR
|
||||
FBBBBFFLLR
|
||||
FFBBFFFLRL
|
||||
FFBFBBFLLR
|
||||
FBFFFBBRRR
|
||||
FBFFBFBLRR
|
||||
FBBFBFFRLR
|
||||
FBBBFBFRLL
|
||||
FFBFFBBRLR
|
||||
FBFBBBFRRL
|
||||
BFFBBBFRRR
|
||||
FBFBBBBLLR
|
||||
FFBFFBBLLL
|
||||
BFFBFBBLLR
|
||||
BFFBFBBRLR
|
||||
BFFBBBBLLL
|
||||
FBBBBFBLLR
|
||||
FFBFBBBLRR
|
||||
FFBFBBFLRR
|
||||
FFFBFBBRRL
|
||||
FFFFFBBRLL
|
||||
BFFFBFFLRR
|
||||
FFFBFBBRLR
|
||||
FBFFBBFLLR
|
||||
BFBFFBBRRR
|
||||
FBBFBBFLRL
|
||||
BFBBFBFRRR
|
||||
BFFFBBBLRL
|
||||
BBFFFBFLLR
|
||||
BFFFFBFLRR
|
||||
BFFBFFBLLL
|
||||
FFBBFBFRRR
|
||||
BFBFFFBLLL
|
||||
FBFBFFFRRR
|
||||
BFBFBBBLLL
|
||||
BFFFBBFLLL
|
||||
BFBFFFBLLR
|
||||
BFFBBBFRRL
|
||||
FFFBBFFLLR
|
||||
BFFBBBFLRR
|
||||
FBFFBBBRLR
|
||||
FBBFBBFLRR
|
||||
FBBFFBFRRR
|
||||
FBBFBBBRRL
|
||||
FFFBFFBRRL
|
||||
FBFBFFBRLL
|
||||
FBFFBBFRLL
|
||||
BFBFBFFRLL
|
||||
FBFBFFFRLR
|
||||
BFBFFBBRRL
|
||||
FFBBFFBRRR
|
||||
BFFBFBBLRL
|
||||
FFBFBFBLLL
|
||||
BBFFFBFRLL
|
||||
FBFBBBFRRR
|
||||
BFFBBFFLRR
|
||||
BFBBFFBLRL
|
||||
BFFFFFBLLL
|
||||
BBFFFFFRLR
|
||||
FBBFFBFRLL
|
||||
FFBFBFFRRR
|
||||
BFBBBBFLRR
|
||||
BFFBBFFRLL
|
||||
BFBBFFBLLL
|
||||
BFFFFFBRRR
|
||||
FBBFFFBLRL
|
||||
FFFBBBFRLR
|
||||
FFBBBFBRRL
|
||||
BFFFBBBRRL
|
||||
FFBFBFBRRR
|
||||
FBBBBBFRRR
|
||||
BBFBFFFRLL
|
||||
FBFFFBBLRR
|
||||
FBFBFFBRRR
|
||||
BFBFBFBRLR
|
||||
FBBBFFFRRL
|
||||
BFBFFFBRLL
|
||||
FBBBFFBLLL
|
||||
BFBFBFFRLR
|
||||
BBFFBFBLRL
|
||||
BBFFBFBRLR
|
||||
BBFBFFFRRR
|
||||
BFBBFFFRLL
|
||||
BFFBBBBRRL
|
||||
FFBFFBFRLL
|
||||
FBBBFBBLRR
|
||||
FBFFFFFRLR
|
||||
FBFFFBFLLR
|
||||
BBFFBFFRRR
|
||||
BFBFBFBRLL
|
||||
BFFBBBBLLR
|
||||
FBBBFBFLLL
|
||||
FFBBFBBRLR
|
||||
FFFFBBFRRR
|
||||
FFFBFFFRRL
|
||||
FFFFBBBLLL
|
||||
FBBBBFBLLL
|
||||
BFBBFBFRLL
|
||||
FFBFBFFRLR
|
||||
FBFBBBFLLL
|
||||
BFBBBFFLLL
|
||||
BBFFBFFRLL
|
||||
FBFFFFFLLR
|
||||
FBBBBFBLRR
|
||||
BFBFFFFRRR
|
||||
BFFBBBBLRL
|
||||
BFFBBFFLLL
|
||||
FBFFBBFLRR
|
||||
BBFFFFBLRR
|
||||
FBBBBFFRLL
|
||||
FBFBFFBRLR
|
||||
FFFFBBFRLR
|
||||
FBBFFBBLLR
|
||||
BFFFBBFLRL
|
||||
BFFFFFFLRR
|
||||
BFBFBFBRRL
|
||||
FFBBFBFLLR
|
||||
BFBBFBFLLR
|
||||
FFBBBFBLRR
|
||||
BBFFBFBRRL
|
||||
BFFBBBFLRL
|
||||
BFFBFFFRRR
|
||||
FFFFBBFLLL
|
||||
BBFFFBBRLR
|
||||
FFBBBBBRLR
|
||||
FFBFBBBRLR
|
||||
FFFFBFBLLR
|
||||
FBBBBBBLLR
|
||||
FBBBFFBLRL
|
||||
BFFFFFFLLL
|
||||
FBBFBBFLLL
|
||||
BFBBBBBLRR
|
||||
FBFBBFBLLL
|
||||
FBFFFBBLLL
|
||||
FBFFFBBRLR
|
||||
FFFBBBFRRL
|
||||
FBFFFFBLLL
|
||||
BBFFFFFRLL
|
||||
BFBFBBFLRL
|
||||
FBBBFFFLLL
|
||||
BFBBFBBRLR
|
||||
FFBFBBFRLL
|
||||
FFBFBFBLRL
|
||||
BFFBBBBRRR
|
||||
FFFFBBFLRL
|
||||
BBFFFFBLLR
|
||||
FFFBBBFLLR
|
||||
FFFBFFFLLR
|
||||
FFBBBFFLRL
|
||||
FBFBBBFLRL
|
||||
FBBFBBFLLR
|
||||
FBFBBFFLLR
|
||||
BBFFBBBRRL
|
||||
FBFBBFBLRR
|
||||
FBBBFFFLLR
|
||||
FBFBFFFRLL
|
||||
FFBBFFBLLL
|
||||
FBBBFBFRRR
|
||||
BFBFFFBRRR
|
||||
FBBBFFFRRR
|
||||
BBFFBBBLLL
|
||||
BFFBFFBRLR
|
||||
BFFFBFBLLR
|
||||
FBBBBBFLRR
|
||||
FBBFBBBLRL
|
||||
FFFBFFFLRR
|
||||
FFFFBBBRRR
|
||||
BBFFFBFLRL
|
||||
FBFBBFFRRL
|
||||
BBFBFFFRLR
|
||||
FBFBFBBRRL
|
||||
FFBFFBFLRL
|
||||
FBFFBFBRLR
|
||||
BFBFFFFLRL
|
||||
FBFFFBFRRR
|
||||
FFFFBFBRRR
|
||||
BBFFFFBRLR
|
||||
FBBBFFBRRL
|
||||
FBBFFBBRLR
|
||||
FFBBFBFLRL
|
||||
BFFFBBBLLR
|
||||
BFFFFFFRLL
|
||||
BFFBBBBLRR
|
||||
BFBFBBBRRL
|
||||
FBFBBBBLLL
|
||||
BBFFFBBLRR
|
||||
FFFFBBFLRR
|
||||
FFBBFBBLRR
|
||||
FFFBBBBLLL
|
||||
FFBBBBFLLL
|
||||
FBBFFFFLLR
|
||||
FFBFBBBRLL
|
||||
FFBBFBBRRR
|
||||
BFBFBBBLLR
|
||||
FBBBBBFLLL
|
||||
FFBBFFBRLL
|
||||
BFBFFBFRLR
|
||||
FBBFBFBRRL
|
||||
FFBBFFFLRR
|
||||
BFBFBFFLRL
|
||||
FBFFBFFRRR
|
||||
BBFFBFFRLR
|
||||
FFBBBBBRRL
|
||||
FBBBFBBLLR
|
||||
FFFBBBBLLR
|
||||
FFBBFBBLLR
|
||||
BBFBFFBLRL
|
||||
BFFFFFBLLR
|
||||
FFFBFFBRLL
|
||||
FFFFBFBRLR
|
||||
FFBFFBBRRR
|
||||
FBBBBFFLRR
|
||||
BFBFFFFRLR
|
||||
FFBBFFBLRL
|
||||
BFBBFBBLLR
|
||||
BBFBFFFLRR
|
||||
FBFFFBBLLR
|
||||
BFFBBBFLLR
|
||||
BFFBBFFLLR
|
||||
BFBBBBFRLR
|
||||
FBFFBBBLLR
|
||||
FFBFFFFLLR
|
||||
FBBBBFFRRL
|
||||
FBFBBFBRRL
|
||||
FFFFBFBLRR
|
||||
BBFFFFBRRR
|
||||
BFBBFBFRRL
|
||||
BFFBBFFRLR
|
||||
FBFBFBFLLR
|
||||
BBFFBFFLRL
|
||||
BBFFBBBLLR
|
||||
BFBBBFBLLL
|
||||
BFBBBBBLLR
|
||||
FBBBFFBRLL
|
||||
FBFFBFBRLL
|
||||
BFBFFBFLLR
|
||||
BFBFFFFLLL
|
||||
FBFFFFFRLL
|
||||
FFBBFFFLLR
|
||||
FFFBFFFRRR
|
||||
FBFFFBFRLR
|
||||
FFFBFBBLLL
|
||||
BBFFFBBLLL
|
||||
FFFBBFBLRL
|
||||
FBBBFBFRRL
|
||||
FFFBBFBRLR
|
||||
BFBBBFFLRR
|
||||
FFBBBFFLRR
|
||||
FFBFBBBLLR
|
||||
FBBFBFBLLR
|
||||
FFBFFBBRRL
|
||||
FFFBFBFLRR
|
||||
FBBFBFBRLL
|
||||
BBFFBBFLRL
|
||||
FBBFFBFRRL
|
||||
BFBFBFFRRR
|
||||
BFBBBFBRRR
|
||||
BFFFFBFLLR
|
||||
FBBFBFBRRR
|
||||
BFFFFBBLLL
|
||||
FFFBFFFRLR
|
||||
FBBFBFBRLR
|
||||
BFFFFBFRLL
|
||||
FFBFBBFRRR
|
||||
BBFFBFBRRR
|
||||
FFBBBFFRLR
|
||||
BFBFBFFRRL
|
||||
BFFFBFBLRR
|
||||
BFBBFBBRRR
|
||||
FFBFFBFRLR
|
||||
BFFFBFFRRL
|
||||
BFBFBBBLRR
|
||||
FFBBBBBRLL
|
||||
BFBBFFBRLR
|
||||
FBFFFFFLRL
|
||||
FFBBBBBRRR
|
||||
FFBFFFBLLL
|
||||
FFBBBBBLLR
|
||||
BBFFBFBRLL
|
||||
BFBFBBBLRL
|
||||
FBBFFFFLRR
|
||||
BBFFBFBLLR
|
||||
FFBBBFBLLR
|
||||
BFBFFFBRLR
|
||||
FBFBBBFLRR
|
||||
FBFBBBBRLL
|
||||
BFFFFBFLRL
|
||||
BFFFBFBRLR
|
||||
FBBFFFFLRL
|
||||
FFFBBBBRLL
|
||||
FFFBFFFRLL
|
||||
FFFFBBBLRL
|
||||
BFFFBFBRLL
|
||||
FBFBBBBLRR
|
||||
BFBBBFFLLR
|
||||
FFFBFFBRLR
|
||||
FBFFBFFLRR
|
||||
FFFFBFFLLL
|
||||
BFFBBBFLLL
|
||||
BFFFBBBRLL
|
||||
FBFFFFBLRL
|
||||
BBFFBBFRLL
|
||||
BFBBBFBLRL
|
||||
FBBFFBBRLL
|
||||
BFBBBBBLLL
|
||||
BFBFBFBLRL
|
||||
BFFBBFBLRL
|
||||
BFFBFFBRRR
|
||||
FFBBBBFLRR
|
||||
FBBBBFBRRR
|
||||
FBBBFBFLLR
|
||||
FFBFBBFLLL
|
||||
BBFFBBFLRR
|
||||
FFFBBFFRLR
|
||||
FBBBFFFRLL
|
||||
FBBBBFFRRR
|
||||
FFFBFBFLLL
|
||||
BBFBFFFLLL
|
||||
FBFFBFBRRR
|
||||
BFFFBFFLRL
|
||||
FFBBBFBLLL
|
||||
FBBBBFBRLR
|
||||
BFBFFBFLLL
|
||||
BFBFBBFLLL
|
||||
FBFBFFBLLL
|
||||
FBBBBFFRLR
|
||||
FBFFBFFRLR
|
||||
BFBFBBFLRR
|
||||
FBFBBBBLRL
|
||||
FFFFBBFRLL
|
||||
FFBFBBBRRR
|
||||
BFFBBFFRRL
|
||||
BBFFBBFRLR
|
||||
FBBFFBFLLR
|
||||
FBFFBFFLLL
|
||||
BBFFFBFRRL
|
||||
FBFFFFBRLL
|
||||
FBFBFBFRRL
|
||||
FFBFFFBLLR
|
||||
BFBFFBBLLL
|
||||
BFBFBFFLRR
|
||||
FBFFBFFRLL
|
||||
BFFBFBFLLR
|
||||
FBFBFFBLRL
|
||||
FFBFBFFRRL
|
||||
FBFBBBBRLR
|
||||
FFFFBBBRLL
|
||||
BFBBFBFLLL
|
||||
FBFFFFFLLL
|
||||
FFBBFBFLRR
|
||||
FFBFBFBRRL
|
||||
FBFFBFBRRL
|
||||
FBFBFBFRLR
|
||||
FFFBBBFLRL
|
||||
BFBBBBBRLR
|
||||
BBFFBBFLLL
|
||||
FBBFBBBLRR
|
||||
FFBBBFBRLL
|
||||
FBFFBBFRRR
|
||||
FFFFBFFLRL
|
||||
FFBFBBFRLR
|
||||
FBBFBFFLRR
|
||||
FFBBFBFLLL
|
||||
FFBFBBBLLL
|
||||
BFFFBBBLLL
|
||||
BFFBBBBRLR
|
||||
BFBBFBBLLL
|
||||
FFBBBFBLRL
|
||||
BFFBBFFRRR
|
||||
FFFBBFBRLL
|
||||
BFBFBFFLLL
|
||||
BFFBBBFRLR
|
||||
BFBFFBBLRR
|
||||
FBBFFFBRRR
|
||||
FBBFFFFRRR
|
||||
BFBFBFBLLR
|
||||
BBFFBBFRRL
|
||||
FFFFBBBRRL
|
||||
FFFBFBFLRL
|
||||
BFFFBFFLLR
|
||||
FFBBFFFRRL
|
||||
FFFBFBBRRR
|
||||
BFFFFBBRRL
|
||||
BFBBFFFLRR
|
||||
BFBFFFFRLL
|
||||
FFFFBBBRLR
|
||||
FFFBBFBLLR
|
||||
FBFBFBFRLL
|
||||
BFBBFBFLRL
|
||||
BFBBBBBRRR
|
||||
FBFFFFBRRL
|
||||
BFBFFFBLRL
|
||||
FBFBBBFRLR
|
||||
BFBFFBFLRR
|
||||
FFBFBFFLRR
|
||||
FFFBBBFRRR
|
||||
FFBBFFBRLR
|
||||
FFBFFFFLRR
|
||||
FBBBFFFLRL
|
||||
BFBBFFBLLR
|
||||
BFFBFBBLRR
|
||||
FBBFBFBLRL
|
||||
BFFFBFBLLL
|
||||
FFFBBFFLRR
|
||||
FBFFFFFRRR
|
||||
BFBFFBFLRL
|
||||
FFBFFFBRRR
|
||||
FBFBFBBLLR
|
||||
FFFFBBBLLR
|
||||
BFBFFFFRRL
|
||||
FFBBFFFRRR
|
||||
FBBBFBFLRL
|
||||
BFBBBFFRLL
|
||||
BFBFFBBLRL
|
||||
BBFFFFFLLR
|
||||
FFBBBFFLLL
|
||||
FFBFFFBRLL
|
||||
FFBBFFBLLR
|
||||
BBFFBFFLLL
|
||||
FBFBBFBRRR
|
||||
FBBBBBFLLR
|
||||
FFBFFFFLRL
|
||||
FBBBBFFLLL
|
||||
BFFBFBFRRR
|
||||
FBFFFFFLRR
|
||||
FFFFBBFLLR
|
||||
FFFBFBFRRL
|
||||
FBFBFBFLRR
|
||||
FBFBBFFRLR
|
||||
BFFFBBFRLR
|
||||
FFBFFBBLRR
|
||||
FFBBFFBRRL
|
||||
BFBFFBFRRL
|
||||
FFFBFFBLRR
|
||||
BFBBFFFRRR
|
||||
BFFBFBFLRL
|
||||
FFBFBBFRRL
|
||||
BFFFBFFLLL
|
||||
FBFFBFBLLL
|
||||
BFBBFFFLLR
|
||||
BFFFFBBLRR
|
||||
FFFBFFFLLL
|
||||
BBFFBBBRLL
|
||||
BFFBFBFLRR
|
||||
FBBFBFFRLL
|
||||
BFFBBBBRLL
|
||||
BFBFBBFLLR
|
||||
FBBBBBBRLR
|
||||
BFBBBBFRRR
|
||||
FFBFFBFLLL
|
||||
BFFFFFBRRL
|
||||
BFFFBFFRLL
|
||||
BFFFBFBLRL
|
||||
FFBBBBFRLR
|
||||
FBBBFFFLRR
|
||||
BFFBFBBRRL
|
||||
BBFFFFFRRR
|
||||
FBBBFBBLLL
|
||||
FFBFFFBLRR
|
||||
FFBBFBBRLL
|
||||
FBFBBFFLLL
|
||||
BFFFBFFRLR
|
||||
BFBBBBBLRL
|
||||
FFFBFFBRRR
|
||||
FFFBBFFLRL
|
||||
FBFBFBBRLL
|
||||
FFFBFBBRLL
|
||||
FFBFBFBRLL
|
||||
FBFFFBFRLL
|
||||
BFFBFBFRRL
|
||||
FBBFFFBRLR
|
||||
BFBBBFFRRR
|
||||
FBBBBBFLRL
|
||||
FFFFFBBRRL
|
||||
FBFFBBFLLL
|
||||
BFBBFBBLRL
|
||||
BFFBBFBLLL
|
||||
FFBFBFFLLL
|
||||
FFFBBBFLLL
|
||||
BFFBFBFLLL
|
||||
FBFFFFBRLR
|
||||
FBFBBFBLRL
|
||||
BBFFFBFRLR
|
||||
FFFBBFBLRR
|
||||
BFFBFFBRLL
|
||||
BFFBBFBRLL
|
||||
FBBFFFFRLR
|
||||
FBBFFFBLLL
|
||||
FFBFFFFRRL
|
||||
FFFFBFFLLR
|
||||
FFFBBFFRLL
|
||||
BFBBBFBRLR
|
||||
BFBFFFBLRR
|
||||
BFFFBBFLRR
|
||||
BFBFFBFRLL
|
||||
BFBBFFBRRL
|
||||
FFFFBBBLRR
|
||||
FBFFFBBLRL
|
||||
FFBBBFFRLL
|
||||
FBBBFBBRLR
|
||||
FFBFFBFRRR
|
||||
FBFBFFFRRL
|
||||
BFBBBFFRLR
|
||||
FFFBBBFLRR
|
||||
FFFFBBFRRL
|
||||
FFBFBFBLRR
|
||||
FFFBFFBLLL
|
||||
FBFFFBBRRL
|
||||
FFFFBFFRLR
|
||||
FFBBBBBLRR
|
||||
FFFFBFFRLL
|
||||
FBFFBBBRRL
|
||||
BFFFFBBLRL
|
||||
FBFFBBBRLL
|
||||
BBFFFFFLRL
|
||||
FBFBBFFLRR
|
||||
FBBBBFBRLL
|
||||
BFFBFFFLLL
|
||||
FBBBFFFRLR
|
||||
BFBBFFBLRR
|
||||
FFBBFBBLLL
|
||||
FBBFFBBRRL
|
||||
BFBFBFBLRR
|
||||
FFFBBFBRRL
|
||||
BBFFFBFLRR
|
||||
FBBBBBBLLL
|
||||
BFFFBFBRRR
|
||||
FBFBFFFLLL
|
||||
FFBBBBBLLL
|
||||
BFBFBFFLLR
|
||||
FBBFFBBLLL
|
||||
FBBBBBBLRL
|
||||
BBFFBBBRLR
|
||||
FBFFFBBRLL
|
||||
BFBFBBBRLL
|
||||
BBFBFFBLLR
|
||||
FFFBBFFRRR
|
||||
FBFBFBBRRR
|
||||
FBBFBFFRRR
|
||||
BFBBBFBRLL
|
||||
FBFBFFBLLR
|
||||
BBFFBFBLLL
|
||||
BFFFBBFRLL
|
||||
FBFBFFFLLR
|
||||
FBFFFFBRRR
|
||||
FFBFBBFLRL
|
||||
BBFFFBFLLL
|
||||
FBBFBBBLLL
|
||||
FBBBFBBRRL
|
||||
FBFBFBFLLL
|
||||
FFFFBFBLRL
|
||||
FFFFFBBRRR
|
||||
FFBFFBBLLR
|
||||
BBFFFFFRRL
|
||||
FBFBBBFLLR
|
||||
BFBBBFFRRL
|
||||
FBFBBFBRLR
|
||||
BFBBBFBLRR
|
||||
FFBFBFFLLR
|
||||
FBFBFFBRRL
|
||||
FFBFBFBRLR
|
||||
BFBFFBBRLL
|
||||
FFBFFFFRRR
|
||||
BFFBBFBRRR
|
||||
FFBBBBFRRL
|
||||
FFFBBBBLRL
|
||||
FFBBBFFRRL
|
||||
BFBBBBFRLL
|
||||
BFBFBFBLLL
|
||||
BFBBFFFRRL
|
||||
BFFBFFBLLR
|
||||
FFBBBFBRLR
|
||||
FFBBFBFRRL
|
||||
FBFFBBBLRR
|
||||
FBBFBBBLLR
|
||||
BFBFFBBLLR
|
||||
BFFFFBFLLL
|
||||
FFFBFBFLLR
|
||||
FBFFFFBLRR
|
||||
FBBFBFBLLL
|
||||
BFFFFBFRLR
|
||||
FBBBFBFRLR
|
||||
FFBBFBFRLR
|
||||
BFFFFFFLLR
|
||||
BFFFFBFRRL
|
||||
BBFFBBFRRR
|
||||
FBFFBFFLRL
|
||||
FBBBBBFRLR
|
||||
FBBBBFBLRL
|
||||
BFFFBBBRRR
|
||||
FFFFBFFRRL
|
||||
FFBFFFFLLL
|
||||
FFFBFBFRLL
|
||||
FFBFFBFLRR
|
||||
FBBFFBFLRL
|
||||
FBBFFBBLRR
|
||||
FFBFFBFRRL
|
||||
BFFFFFFRRR
|
||||
BFBFBBBRLR
|
||||
BFFBFBBRLL
|
||||
BBFFBFFRRL
|
||||
FBBFBBFRLL
|
||||
BFFFFFBRLR
|
||||
BFBBBBFLLL
|
||||
BFBBFFBRRR
|
||||
FFFFBFBLLL
|
||||
FFBBFFFRLR
|
||||
BFBBBFBRRL
|
||||
BFFFBBFRRR
|
||||
FBFFFFFRRL
|
||||
BFFBFFFRLL
|
||||
BFFFFBBRLR
|
||||
FFBBFFBLRR
|
||||
BBFFBBBLRR
|
||||
FBBFFFFRRL
|
||||
BFFFFBBRLL
|
||||
BFFFFFBRLL
|
||||
BFBFFFFLLR
|
||||
FBBBBBFRRL
|
||||
FBFBBBBRRR
|
||||
FBBFBBFRRL
|
||||
FBBBFBBRLL
|
||||
FBFFBFFLLR
|
||||
FFBFFFFRLR
|
||||
BFFFFFFRRL
|
||||
BFBBFFFRLR
|
||||
FFBBBBFLRL
|
||||
FFBFFBBRLL
|
||||
FFBBFBBLRL
|
||||
FBFBFFBLRR
|
||||
BFFBFBFRLR
|
||||
FBFFBBBRRR
|
||||
FBBBBFFLRL
|
||||
FBBFBFFRRL
|
||||
FFBFBFFLRL
|
||||
BFFBBFBRLR
|
||||
BBFFFFFLRR
|
||||
FBBFFFBRLL
|
||||
BFFFBFBRRL
|
||||
FFBFBFFRLL
|
||||
BBFFBBBRRR
|
||||
BBFFFFBLRL
|
||||
BBFFFBBRRR
|
||||
BBFFFFBRLL
|
||||
FBBFFBFLLL
|
||||
BFFFBBBLRR
|
||||
FFBFFBFLLR
|
||||
FBBFBFFLLR
|
||||
FBFBBFFLRL
|
||||
FBBBBFBRRL
|
||||
BFBBFBFLRR
|
||||
BBFFBFBLRR
|
||||
FFFBBBBLRR
|
||||
FBBBFFBRLR
|
||||
FBFBFBBLRR
|
||||
FBBBFBBRRR
|
||||
BFBBFFFLLL
|
||||
BFFFFBBLLR
|
||||
FBBBBBBRLL
|
||||
FBBBFBBLRL
|
||||
FBBBBBBRRR
|
||||
FFFBBBFRLL
|
||||
BBFFFFFLLL
|
||||
FBBFFBFRLR
|
||||
BFBBBBFLRL
|
||||
BFFFFBFRRR
|
||||
FBFFBBBLRL
|
||||
BFBBFBBRRL
|
||||
FBFFBFBLRL
|
||||
FFFBBFBRRR
|
||||
BFBFBBBRRR
|
||||
BFBBFFFLRL
|
||||
BBFFFBBRRL
|
||||
FFFBBBBRRL
|
||||
FBBBFFBLLR
|
||||
FBFBFFFLRR
|
||||
FBFBFBBRLR
|
||||
BFFFBBFRRL
|
||||
FBFBFBFRRR
|
||||
FBBFFFFLLL
|
||||
FBBFFBBLRL
|
||||
FBBBFBFLRR
|
||||
FFFBBFFLLL
|
||||
BFFBFFBRRL
|
||||
BFFFFBBRRR
|
||||
FFFFFBBRLR
|
||||
BBFFBBBLRL
|
||||
FBBFBBFRRR
|
||||
BFBBFBBLRR
|
||||
FFBFFFFRLL
|
||||
BFBFFFBRRL
|
||||
FBBFBBBRLL
|
||||
FBFBBFBRLL
|
||||
FBFFFBFRRL
|
||||
BFFBFFBLRR
|
||||
FBBFBFBLRR
|
||||
BFBBBBFLLR
|
||||
BFBBBFBLLR
|
||||
FFFFBFBRRL
|
||||
FFFBBBBRLR
|
||||
FFBFFFBRLR
|
||||
BFFBFFBLRL
|
||||
FBBFBFFLLL
|
||||
BFFBFBBLLL
|
||||
FBFBBFBLLR
|
||||
FBBFFBFLRR
|
||||
FFBBBBFLLR
|
||||
FBBFBFFLRL
|
||||
FFFBFBBLRL
|
||||
FBBFFFFRLL
|
||||
BFBFBBFRRR
|
||||
FBFFBBBLLL
|
||||
FFBFBBBLRL
|
||||
BBFFBBFLLR
|
||||
FBFFFBFLLL
|
||||
BFBFBFBRRR
|
||||
BFBBBBBRRL
|
||||
BBFBFFBLLL
|
||||
BFFFFFFLRL
|
||||
FBBFFFBRRL
|
||||
FFBBFBFRLL
|
||||
BBFFBFFLLR
|
||||
BBFBFFFRRL
|
||||
FFFBBFBLLL
|
||||
BFFBFFFRRL
|
||||
BFBBBBBRLL
|
||||
FFFBFBFRLR
|
||||
FBFFBBFRRL
|
||||
BFFBFFFLLR
|
||||
FFBBFFFLLL
|
||||
BFFBBBFRLL
|
||||
FFBBBBFRLL
|
||||
FFFFBFFLRR
|
||||
FFBBBBBLRL
|
||||
FBBBBBBLRR
|
||||
FBBFFFBLLR
|
||||
BBFFFBBRLL
|
||||
BFFBBFFLRL
|
||||
FFFBFBFRRR
|
||||
FBFBFBBLLL
|
||||
FBBBBBFRLL
|
||||
FBBBBBBRRL
|
||||
FBFBBBBRRL
|
||||
FBFFBFFRRL
|
||||
BFFFBBFLLR
|
||||
BFFBFFFLRR
|
||||
BFFBBFBLRR
|
||||
FFFFBFBRLL
|
||||
BFFBFFFLRL
|
||||
FFBFFFBLRL
|
||||
FBBFFFBLRR
|
||||
BFBBBFFLRL
|
||||
FBFFBBFLRL
|
||||
BFFFBBBRLR
|
||||
BFFBFBBRRR
|
||||
BFFFFFBLRL
|
||||
BBFBFFFLRL
|
||||
BFBFBBFRRL
|
||||
BBFFBFFLRR
|
||||
FBFBFBBLRL
|
||||
BFBFBBFRLR
|
||||
FFFBBBBRRR
|
||||
FBFFFFBLLR
|
||||
FBFBBFFRLL
|
||||
BFBFFBFRRR
|
||||
FFFBFFBLLR
|
||||
FBFBFBFLRL
|
||||
FBBFBBBRLR
|
||||
FFFBFBBLLR
|
||||
FFBBFFFRLL
|
||||
BFBFFBBRLR
|
||||
BBFFFFBLLL
|
||||
FFBBBFFRRR
|
||||
BFFBFFFRLR
|
||||
FFBFFBBLRL
|
||||
FBBBFFBRRR
|
||||
BFBFBBFRLL
|
||||
BFBBBBFRRL
|
||||
BFBBFFBRLL
|
||||
BBFFFBBLRL
|
||||
FFBBBBFRRR
|
||||
BBFFFBFRRR
|
||||
BFBFFFFLRR
|
||||
FFFBFBBLRR
|
||||
BFFBBFBRRL
|
||||
FBBFBBBRRR
|
||||
FBFBFFFLRL
|
||||
BFBBFBFRLR
|
||||
FFFBFFFLRL
|
||||
FFBBBFBRRR
|
||||
FBBFFBBRRR
|
||||
BBFFFBBLLR
|
||||
FFFBFFBLRL
|
||||
FFBFBBBRRL
|
||||
FFBBBFFLLR
|
||||
FBFFBBFRLR
|
||||
FBFFFBFLRL
|
||||
FFBBFBBRRL
|
||||
FFFBBFFRRL
|
||||
FBBFBBFRLR
|
||||
FBFBBFFRRR
|
||||
FFFFBFFRRR
|
||||
BFFFFFBLRR
|
||||
BBFFFFBRRL
|
||||
FBBBFFBLRR
|
||||
BFFBFBFRLL
|
||||
FFBFFFBRRL
|
||||
FFBFBFBLLR
|
||||
BIN
c/2020/5/main
Executable file
BIN
c/2020/5/main
Executable file
Binary file not shown.
54
c/2020/5/main.c
Normal file
54
c/2020/5/main.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
int seat_id_from_boarding_pass(char *boarding_pass) {
|
||||
int seat_id = 0;
|
||||
while(*boarding_pass) {
|
||||
if (*boarding_pass == 'B' || *boarding_pass == 'R') seat_id++;
|
||||
seat_id <<= 1;
|
||||
boarding_pass++;
|
||||
}
|
||||
seat_id >>= 1;
|
||||
return seat_id;
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
char *data_buffer = load_input();
|
||||
char *boarding_pass = strtok(data_buffer, "\n");
|
||||
int max_seat_id = 0;
|
||||
do {
|
||||
int seat_id = seat_id_from_boarding_pass(boarding_pass);
|
||||
if (seat_id > max_seat_id) max_seat_id = seat_id;
|
||||
} while (boarding_pass = strtok(NULL, "\n"));
|
||||
|
||||
free(data_buffer);
|
||||
return max_seat_id;
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
bool occupied_seats[1028] = {0};
|
||||
char *data_buffer = load_input();
|
||||
char *boarding_pass = strtok(data_buffer, "\n");
|
||||
int max_seat_id = 0;
|
||||
do {
|
||||
int seat_id = seat_id_from_boarding_pass(boarding_pass);
|
||||
occupied_seats[seat_id] = true;
|
||||
if (seat_id > max_seat_id) max_seat_id = seat_id;
|
||||
} while (boarding_pass = strtok(NULL, "\n"));
|
||||
|
||||
bool occupied_seat = occupied_seats[max_seat_id];
|
||||
while(occupied_seat) {
|
||||
max_seat_id--;
|
||||
occupied_seat = occupied_seats[max_seat_id];
|
||||
}
|
||||
|
||||
free(data_buffer);
|
||||
return max_seat_id;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
2190
c/2020/6/input.txt
Normal file
2190
c/2020/6/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
c/2020/6/main
Executable file
BIN
c/2020/6/main
Executable file
Binary file not shown.
89
c/2020/6/main.c
Normal file
89
c/2020/6/main.c
Normal file
@ -0,0 +1,89 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
typedef uint question_bits;
|
||||
|
||||
int question_score(question_bits q) {
|
||||
int score = 0;
|
||||
while(q) {
|
||||
score += q & 1;
|
||||
q >>= 1;
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
InputWithSize *input = load_input_with_size();
|
||||
bool questions[26] = {0};
|
||||
question_bits q = 0;
|
||||
|
||||
int sum = 0;
|
||||
int offset = 0;
|
||||
do {
|
||||
char c = *(input->data_buffer + offset);
|
||||
if (c == '\n') {
|
||||
if (*(input->data_buffer + offset + 1) == '\n') {
|
||||
int count = question_score(q);
|
||||
q = 0;
|
||||
sum += count;
|
||||
offset++;
|
||||
}
|
||||
} else {
|
||||
q |= 1 << (c - 'a');
|
||||
}
|
||||
offset++;
|
||||
} while(offset < input->size);
|
||||
|
||||
int count = question_score(q);
|
||||
sum += count;
|
||||
|
||||
sum--; // No idea
|
||||
|
||||
free_input_with_size(input);
|
||||
return sum;
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
InputWithSize *input = load_input_with_size();
|
||||
bool questions[26] = {0};
|
||||
question_bits group = UINT_MAX;
|
||||
question_bits member = 0;
|
||||
|
||||
int sum = 0;
|
||||
int offset = 0;
|
||||
do {
|
||||
char c = *(input->data_buffer + offset);
|
||||
if (c == '\n') {
|
||||
if (*(input->data_buffer + offset + 1) == '\n') {
|
||||
group &= member;
|
||||
int count = question_score(group);
|
||||
group = UINT_MAX;
|
||||
member = 0;
|
||||
sum += count;
|
||||
offset++;
|
||||
} else {
|
||||
group &= member;
|
||||
member = 0;
|
||||
}
|
||||
} else {
|
||||
member |= (1 << (c - 'a'));
|
||||
}
|
||||
offset++;
|
||||
} while(offset < input->size);
|
||||
|
||||
char c = *(input->data_buffer + offset);
|
||||
member = 0;
|
||||
int count = question_score(group);
|
||||
sum += count;
|
||||
|
||||
free_input_with_size(input);
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
594
c/2020/7/input.txt
Normal file
594
c/2020/7/input.txt
Normal file
@ -0,0 +1,594 @@
|
||||
shiny indigo bags contain 4 vibrant lime bags.
|
||||
clear lime bags contain 1 dotted lime bag, 2 clear gold bags.
|
||||
dotted turquoise bags contain 2 shiny green bags, 5 striped magenta bags, 3 muted green bags.
|
||||
bright red bags contain 1 plaid magenta bag, 3 light cyan bags.
|
||||
vibrant magenta bags contain 5 drab lime bags, 3 muted red bags, 3 wavy turquoise bags, 3 mirrored salmon bags.
|
||||
plaid violet bags contain 4 plaid indigo bags, 1 mirrored beige bag.
|
||||
muted gray bags contain 2 striped crimson bags, 2 striped maroon bags, 1 faded maroon bag, 4 dim lavender bags.
|
||||
mirrored crimson bags contain 5 muted lavender bags.
|
||||
muted gold bags contain 3 striped plum bags, 4 bright coral bags.
|
||||
pale black bags contain 4 shiny orange bags, 3 pale bronze bags, 2 wavy coral bags.
|
||||
muted purple bags contain 5 muted brown bags.
|
||||
clear cyan bags contain 4 muted white bags.
|
||||
shiny blue bags contain 5 pale magenta bags, 3 drab coral bags.
|
||||
posh white bags contain 3 posh brown bags, 3 striped gold bags, 1 faded gray bag.
|
||||
muted beige bags contain 1 pale teal bag.
|
||||
clear purple bags contain 4 plaid turquoise bags.
|
||||
pale gold bags contain 1 mirrored lime bag, 2 dim crimson bags, 3 dim aqua bags, 2 dull silver bags.
|
||||
pale beige bags contain 4 drab olive bags, 2 wavy coral bags.
|
||||
drab black bags contain 4 mirrored blue bags, 2 light olive bags.
|
||||
faded purple bags contain 3 dim lime bags, 2 vibrant violet bags.
|
||||
pale silver bags contain 3 light cyan bags.
|
||||
plaid teal bags contain 3 dotted fuchsia bags, 3 bright teal bags.
|
||||
plaid beige bags contain 5 shiny black bags, 3 dotted maroon bags.
|
||||
light silver bags contain 3 posh chartreuse bags, 4 dark bronze bags, 1 vibrant silver bag, 2 muted coral bags.
|
||||
pale plum bags contain 5 drab silver bags, 4 light crimson bags.
|
||||
striped cyan bags contain 3 wavy tan bags, 5 pale teal bags, 5 clear orange bags, 3 wavy violet bags.
|
||||
plaid red bags contain 2 dim lavender bags, 4 striped maroon bags.
|
||||
dark salmon bags contain 5 bright gold bags, 5 muted lavender bags, 5 light beige bags.
|
||||
shiny purple bags contain 2 plaid silver bags, 2 mirrored green bags, 3 bright violet bags.
|
||||
shiny turquoise bags contain 1 vibrant salmon bag.
|
||||
muted orange bags contain 2 striped indigo bags, 1 striped crimson bag.
|
||||
pale turquoise bags contain 3 light silver bags, 5 light crimson bags.
|
||||
light indigo bags contain 4 vibrant white bags, 5 plaid yellow bags.
|
||||
faded coral bags contain 1 vibrant beige bag, 4 muted white bags.
|
||||
dim red bags contain 1 mirrored cyan bag, 2 wavy indigo bags, 5 shiny chartreuse bags, 5 muted yellow bags.
|
||||
striped fuchsia bags contain 2 faded salmon bags, 1 pale beige bag, 2 posh magenta bags, 2 wavy green bags.
|
||||
bright green bags contain 4 pale turquoise bags, 2 bright chartreuse bags, 5 posh yellow bags, 4 shiny gold bags.
|
||||
light blue bags contain 5 dim silver bags.
|
||||
vibrant purple bags contain 3 wavy indigo bags, 1 pale maroon bag, 3 drab chartreuse bags, 5 vibrant aqua bags.
|
||||
light coral bags contain 2 clear orange bags, 3 shiny fuchsia bags, 3 striped chartreuse bags.
|
||||
striped maroon bags contain 4 vibrant tomato bags, 2 dull salmon bags, 1 shiny gold bag, 2 muted coral bags.
|
||||
drab lime bags contain 1 mirrored violet bag, 4 posh magenta bags.
|
||||
dotted gold bags contain 3 muted silver bags.
|
||||
pale magenta bags contain 5 mirrored orange bags, 4 pale teal bags.
|
||||
dim olive bags contain no other bags.
|
||||
mirrored blue bags contain 1 dim indigo bag, 4 bright lime bags, 1 plaid beige bag.
|
||||
plaid bronze bags contain 3 pale gold bags.
|
||||
faded aqua bags contain 3 muted aqua bags, 3 muted gray bags, 4 dim olive bags.
|
||||
light gold bags contain 1 mirrored crimson bag, 3 pale tan bags, 3 dotted yellow bags, 2 wavy aqua bags.
|
||||
dim gold bags contain 4 plaid tomato bags.
|
||||
faded chartreuse bags contain 5 muted coral bags, 4 vibrant indigo bags, 1 faded teal bag, 1 vibrant bronze bag.
|
||||
posh brown bags contain 2 muted gray bags, 1 dark plum bag, 3 bright lime bags, 2 dull turquoise bags.
|
||||
mirrored lime bags contain 1 shiny indigo bag, 4 dark olive bags, 3 pale beige bags.
|
||||
posh cyan bags contain 3 pale olive bags.
|
||||
dark lime bags contain 3 shiny cyan bags, 4 bright green bags.
|
||||
drab lavender bags contain 4 drab plum bags.
|
||||
vibrant orange bags contain 5 wavy olive bags.
|
||||
faded violet bags contain 1 faded aqua bag, 2 muted gray bags.
|
||||
light green bags contain 5 pale brown bags, 4 dark aqua bags, 5 vibrant teal bags, 1 pale black bag.
|
||||
bright turquoise bags contain 4 striped teal bags, 2 dim magenta bags, 5 striped orange bags, 4 bright aqua bags.
|
||||
mirrored indigo bags contain 2 wavy violet bags, 2 muted white bags, 2 dim lavender bags.
|
||||
wavy green bags contain 5 dotted teal bags.
|
||||
light aqua bags contain 4 posh lime bags, 1 dotted maroon bag, 3 dotted gray bags, 2 plaid bronze bags.
|
||||
muted tomato bags contain 3 mirrored tomato bags, 3 pale blue bags, 2 mirrored violet bags, 4 drab tomato bags.
|
||||
posh beige bags contain 5 faded aqua bags.
|
||||
shiny coral bags contain 5 striped gold bags, 1 drab coral bag, 2 light lavender bags, 4 striped blue bags.
|
||||
posh orange bags contain 5 dark olive bags, 3 light silver bags, 3 striped gray bags, 2 faded fuchsia bags.
|
||||
posh violet bags contain 2 drab turquoise bags, 5 mirrored gray bags.
|
||||
pale brown bags contain 2 bright chartreuse bags.
|
||||
shiny green bags contain 2 mirrored magenta bags.
|
||||
faded salmon bags contain 2 wavy tan bags.
|
||||
dark gold bags contain no other bags.
|
||||
clear black bags contain 5 vibrant lime bags.
|
||||
muted fuchsia bags contain 1 pale fuchsia bag, 4 mirrored white bags, 3 clear fuchsia bags, 3 faded maroon bags.
|
||||
drab fuchsia bags contain 1 bright chartreuse bag, 3 pale beige bags, 5 wavy brown bags.
|
||||
mirrored plum bags contain 1 plaid yellow bag, 2 dim beige bags, 5 dim aqua bags, 4 dim crimson bags.
|
||||
dark maroon bags contain 1 striped crimson bag, 5 muted fuchsia bags, 3 vibrant silver bags, 2 drab olive bags.
|
||||
drab green bags contain 5 faded bronze bags, 2 bright violet bags, 3 dark gold bags.
|
||||
drab purple bags contain 3 plaid orange bags, 4 striped black bags, 5 vibrant indigo bags, 4 pale turquoise bags.
|
||||
dotted silver bags contain 1 clear crimson bag, 2 faded yellow bags.
|
||||
dull olive bags contain 3 muted salmon bags, 2 vibrant cyan bags, 3 posh bronze bags, 5 light cyan bags.
|
||||
posh gold bags contain 4 bright violet bags, 1 drab yellow bag.
|
||||
dark plum bags contain 4 clear fuchsia bags, 2 mirrored aqua bags.
|
||||
dim purple bags contain 5 clear chartreuse bags, 4 dark gold bags.
|
||||
drab tomato bags contain 5 mirrored white bags.
|
||||
mirrored chartreuse bags contain 3 clear indigo bags, 4 clear crimson bags.
|
||||
striped olive bags contain 4 posh orange bags, 5 shiny indigo bags.
|
||||
dark purple bags contain 2 drab lavender bags, 2 faded bronze bags.
|
||||
light purple bags contain 1 vibrant lime bag, 2 vibrant gray bags.
|
||||
mirrored green bags contain 4 mirrored cyan bags.
|
||||
bright lavender bags contain 1 dark red bag, 2 clear yellow bags, 3 bright brown bags, 2 bright teal bags.
|
||||
posh tomato bags contain 4 posh silver bags, 3 shiny black bags, 4 clear crimson bags, 3 dotted chartreuse bags.
|
||||
dotted coral bags contain 4 dotted bronze bags, 5 dotted maroon bags.
|
||||
pale cyan bags contain 2 dim coral bags, 4 dotted brown bags.
|
||||
plaid gold bags contain 4 bright chartreuse bags, 4 faded bronze bags.
|
||||
bright tan bags contain 3 bright brown bags.
|
||||
dim chartreuse bags contain 2 clear maroon bags, 3 pale tan bags, 2 mirrored lime bags, 1 wavy crimson bag.
|
||||
dark bronze bags contain 4 faded maroon bags, 1 wavy violet bag, 4 plaid silver bags.
|
||||
wavy brown bags contain 4 light red bags, 2 dull tomato bags, 5 mirrored red bags, 4 bright lime bags.
|
||||
dim fuchsia bags contain 4 dark beige bags.
|
||||
drab bronze bags contain 2 dotted blue bags.
|
||||
bright plum bags contain 2 plaid orange bags.
|
||||
shiny red bags contain 1 faded fuchsia bag.
|
||||
vibrant brown bags contain 3 faded fuchsia bags, 2 light plum bags.
|
||||
pale tan bags contain 3 dark aqua bags, 3 dark plum bags, 1 mirrored green bag.
|
||||
dull aqua bags contain 3 muted cyan bags, 5 drab cyan bags.
|
||||
dark teal bags contain 1 light red bag, 4 plaid silver bags, 2 dark olive bags, 5 striped maroon bags.
|
||||
pale tomato bags contain 4 dim indigo bags, 4 dark salmon bags.
|
||||
faded silver bags contain 5 dim blue bags.
|
||||
striped lime bags contain 2 bright black bags.
|
||||
plaid coral bags contain 4 dull salmon bags, 5 mirrored green bags, 1 pale aqua bag.
|
||||
clear white bags contain 4 drab turquoise bags, 2 posh coral bags, 5 dark fuchsia bags.
|
||||
dark turquoise bags contain 1 wavy lavender bag, 4 bright lime bags.
|
||||
dark tomato bags contain 5 faded maroon bags, 4 dark chartreuse bags, 5 wavy fuchsia bags, 2 dotted purple bags.
|
||||
striped bronze bags contain no other bags.
|
||||
dark black bags contain 2 dotted chartreuse bags, 3 pale bronze bags.
|
||||
dotted teal bags contain 2 dark teal bags.
|
||||
drab yellow bags contain 3 dark turquoise bags, 4 muted fuchsia bags.
|
||||
wavy salmon bags contain 2 plaid turquoise bags.
|
||||
dull violet bags contain 3 mirrored red bags, 5 shiny black bags, 3 dark maroon bags.
|
||||
muted cyan bags contain 4 mirrored black bags, 4 dim olive bags, 1 bright chartreuse bag, 1 clear bronze bag.
|
||||
clear plum bags contain 4 light teal bags, 1 faded white bag, 3 striped lime bags.
|
||||
light red bags contain 3 mirrored orange bags.
|
||||
pale gray bags contain 5 wavy cyan bags, 2 bright green bags, 3 striped gray bags.
|
||||
posh green bags contain 3 clear purple bags.
|
||||
dark crimson bags contain 5 bright violet bags, 4 light magenta bags, 1 posh chartreuse bag, 1 shiny gray bag.
|
||||
dull yellow bags contain 1 dotted fuchsia bag, 5 muted maroon bags, 1 muted salmon bag.
|
||||
plaid plum bags contain 1 striped olive bag.
|
||||
wavy lime bags contain 3 vibrant silver bags, 5 shiny gold bags.
|
||||
dim green bags contain 1 dark tomato bag, 5 light red bags, 4 muted gold bags.
|
||||
mirrored yellow bags contain 1 vibrant tomato bag.
|
||||
dotted yellow bags contain 3 striped crimson bags.
|
||||
drab turquoise bags contain 1 clear indigo bag, 1 mirrored magenta bag, 4 clear violet bags.
|
||||
dim aqua bags contain 3 wavy coral bags, 1 posh beige bag.
|
||||
pale violet bags contain 1 faded plum bag, 4 dull purple bags, 2 pale brown bags.
|
||||
muted crimson bags contain 3 dim beige bags, 2 dim gray bags.
|
||||
mirrored brown bags contain 1 dotted tan bag, 4 dim olive bags, 1 bright lime bag.
|
||||
dotted crimson bags contain 5 striped beige bags, 4 striped turquoise bags, 3 shiny fuchsia bags.
|
||||
mirrored tan bags contain 5 bright indigo bags, 3 light violet bags.
|
||||
striped black bags contain 4 striped olive bags.
|
||||
faded fuchsia bags contain 3 faded teal bags, 4 dull salmon bags, 3 light red bags.
|
||||
dull green bags contain 4 mirrored coral bags.
|
||||
vibrant blue bags contain 1 striped gray bag, 4 striped olive bags, 3 wavy brown bags, 3 faded maroon bags.
|
||||
vibrant plum bags contain 4 wavy brown bags, 5 clear violet bags, 3 pale turquoise bags, 2 posh crimson bags.
|
||||
wavy fuchsia bags contain 5 wavy olive bags.
|
||||
striped red bags contain 2 pale yellow bags, 3 pale chartreuse bags, 1 dim blue bag.
|
||||
muted blue bags contain 2 posh red bags, 2 muted red bags, 3 dark tomato bags.
|
||||
muted plum bags contain 4 plaid red bags.
|
||||
clear violet bags contain 5 muted salmon bags.
|
||||
pale white bags contain 3 plaid lavender bags, 5 mirrored green bags.
|
||||
clear beige bags contain 2 vibrant blue bags, 5 muted white bags, 2 dull chartreuse bags.
|
||||
vibrant fuchsia bags contain 4 posh gray bags, 5 dull tomato bags, 3 dim crimson bags.
|
||||
dim indigo bags contain 1 bright black bag, 5 faded black bags, 5 dull turquoise bags, 2 mirrored lime bags.
|
||||
dotted lime bags contain 3 light lime bags, 4 pale salmon bags, 4 dark aqua bags.
|
||||
posh teal bags contain 3 pale gold bags, 2 faded silver bags.
|
||||
faded gray bags contain 2 shiny gold bags, 1 dull turquoise bag, 1 faded chartreuse bag.
|
||||
dim magenta bags contain 2 mirrored aqua bags, 5 wavy orange bags, 3 pale turquoise bags.
|
||||
shiny fuchsia bags contain 5 vibrant silver bags.
|
||||
drab teal bags contain 3 posh magenta bags, 2 striped indigo bags, 5 muted salmon bags, 4 shiny plum bags.
|
||||
bright indigo bags contain 2 faded teal bags.
|
||||
muted teal bags contain 4 mirrored green bags, 3 dull violet bags, 3 shiny purple bags.
|
||||
light tan bags contain 1 muted salmon bag, 1 plaid olive bag, 2 plaid silver bags.
|
||||
striped yellow bags contain 2 drab salmon bags, 2 faded aqua bags.
|
||||
mirrored olive bags contain 5 clear maroon bags, 2 striped coral bags, 4 dim gold bags.
|
||||
wavy cyan bags contain 3 plaid lavender bags, 1 wavy turquoise bag, 2 plaid bronze bags, 1 light beige bag.
|
||||
mirrored red bags contain no other bags.
|
||||
light yellow bags contain 3 dim purple bags, 4 posh green bags, 3 pale gold bags.
|
||||
dotted gray bags contain 3 dotted orange bags, 5 plaid turquoise bags, 4 drab magenta bags.
|
||||
faded red bags contain 3 bright aqua bags.
|
||||
dull teal bags contain 4 clear purple bags, 5 faded turquoise bags.
|
||||
light salmon bags contain 3 posh lime bags, 1 clear lime bag, 1 drab chartreuse bag, 3 clear magenta bags.
|
||||
dark red bags contain 1 plaid tomato bag, 1 plaid orange bag, 4 dotted white bags.
|
||||
mirrored beige bags contain 3 mirrored violet bags, 3 clear orange bags, 3 dark olive bags.
|
||||
drab indigo bags contain 2 muted aqua bags, 3 bright teal bags.
|
||||
light lime bags contain 4 light indigo bags, 5 plaid white bags.
|
||||
pale blue bags contain 3 wavy tan bags, 1 mirrored tomato bag, 5 faded magenta bags, 2 posh crimson bags.
|
||||
drab plum bags contain 2 striped crimson bags.
|
||||
striped tomato bags contain 1 dark maroon bag.
|
||||
faded maroon bags contain 3 drab salmon bags, 5 posh lime bags, 4 dim olive bags, 5 striped bronze bags.
|
||||
clear fuchsia bags contain 5 vibrant silver bags, 5 posh lime bags, 4 striped crimson bags.
|
||||
bright maroon bags contain 2 dull gray bags, 4 bright magenta bags, 5 clear beige bags, 5 vibrant silver bags.
|
||||
clear blue bags contain 4 faded black bags, 2 plaid magenta bags, 1 clear salmon bag, 1 shiny chartreuse bag.
|
||||
plaid chartreuse bags contain 1 dark bronze bag, 1 clear red bag, 2 mirrored plum bags, 4 posh white bags.
|
||||
pale crimson bags contain 4 muted silver bags.
|
||||
clear olive bags contain 3 dark olive bags, 5 drab plum bags, 2 striped maroon bags, 5 shiny purple bags.
|
||||
vibrant indigo bags contain 1 vibrant silver bag, 5 dark olive bags, 1 striped chartreuse bag, 1 muted fuchsia bag.
|
||||
dim coral bags contain 2 dark yellow bags, 3 clear orange bags, 2 clear cyan bags, 1 pale turquoise bag.
|
||||
shiny white bags contain 3 drab teal bags, 3 vibrant blue bags.
|
||||
vibrant tan bags contain 3 posh red bags, 1 faded black bag, 3 faded aqua bags, 2 light beige bags.
|
||||
wavy plum bags contain 1 dotted teal bag, 3 dark indigo bags.
|
||||
drab coral bags contain 3 clear orange bags, 4 shiny red bags, 5 bright teal bags.
|
||||
mirrored aqua bags contain 3 mirrored cyan bags, 5 wavy coral bags.
|
||||
vibrant gray bags contain 2 muted coral bags, 1 clear fuchsia bag.
|
||||
faded turquoise bags contain 2 posh lime bags.
|
||||
clear green bags contain 4 posh yellow bags, 3 light bronze bags, 4 drab gray bags, 3 bright teal bags.
|
||||
wavy gold bags contain 3 faded black bags, 4 faded violet bags.
|
||||
shiny tan bags contain 4 mirrored gray bags, 3 mirrored magenta bags, 5 light red bags.
|
||||
plaid turquoise bags contain 5 faded aqua bags, 3 mirrored tomato bags, 5 light tan bags, 2 drab olive bags.
|
||||
pale bronze bags contain 5 drab chartreuse bags, 4 faded lime bags.
|
||||
mirrored lavender bags contain 3 plaid green bags, 1 clear salmon bag, 3 dim gray bags.
|
||||
pale yellow bags contain 3 drab yellow bags, 5 drab green bags, 1 drab lavender bag, 1 clear magenta bag.
|
||||
mirrored teal bags contain 5 posh black bags.
|
||||
vibrant teal bags contain 1 dark teal bag.
|
||||
bright gold bags contain 3 dark green bags, 4 clear orange bags, 1 shiny purple bag, 5 dull chartreuse bags.
|
||||
muted lavender bags contain 5 faded fuchsia bags.
|
||||
light gray bags contain 5 plaid magenta bags, 3 vibrant cyan bags, 3 bright gold bags, 2 dim cyan bags.
|
||||
dark gray bags contain 3 posh silver bags, 1 dark fuchsia bag, 5 dark teal bags, 5 clear fuchsia bags.
|
||||
mirrored gold bags contain 5 dim crimson bags, 2 plaid beige bags, 3 dark coral bags.
|
||||
wavy violet bags contain 5 dull silver bags, 3 dark gold bags, 5 striped bronze bags.
|
||||
vibrant cyan bags contain 2 bright indigo bags.
|
||||
dull tan bags contain 2 shiny indigo bags, 2 dim gold bags, 5 vibrant blue bags, 4 dull tomato bags.
|
||||
dim orange bags contain 5 posh silver bags, 3 light red bags.
|
||||
drab gold bags contain 4 shiny indigo bags, 2 clear indigo bags, 1 faded fuchsia bag, 1 muted crimson bag.
|
||||
vibrant bronze bags contain 3 mirrored green bags, 2 striped gold bags, 5 wavy coral bags.
|
||||
light violet bags contain 3 dull turquoise bags, 5 light white bags, 2 drab coral bags.
|
||||
plaid tomato bags contain 1 wavy tan bag, 2 faded maroon bags.
|
||||
faded black bags contain 4 dark bronze bags.
|
||||
drab violet bags contain 2 pale green bags, 5 muted olive bags.
|
||||
dull lavender bags contain 5 light chartreuse bags, 5 striped fuchsia bags, 2 clear white bags, 5 dull indigo bags.
|
||||
light chartreuse bags contain 5 dim lavender bags.
|
||||
dim salmon bags contain 5 shiny silver bags, 4 dark coral bags, 2 vibrant cyan bags, 3 faded black bags.
|
||||
posh blue bags contain 4 clear bronze bags, 5 shiny aqua bags, 1 vibrant brown bag.
|
||||
light crimson bags contain 4 plaid aqua bags, 3 mirrored green bags.
|
||||
striped plum bags contain 5 plaid white bags, 5 light beige bags.
|
||||
shiny bronze bags contain 5 dark magenta bags.
|
||||
dark fuchsia bags contain 5 posh crimson bags, 3 dark turquoise bags, 1 vibrant white bag.
|
||||
striped coral bags contain 5 dim gray bags.
|
||||
vibrant gold bags contain 5 dull tomato bags, 3 mirrored cyan bags, 2 light tan bags.
|
||||
wavy tan bags contain 2 faded maroon bags, 4 wavy violet bags.
|
||||
dotted violet bags contain 5 shiny blue bags.
|
||||
faded bronze bags contain 3 shiny gold bags.
|
||||
plaid tan bags contain 3 posh tan bags, 5 mirrored cyan bags, 1 drab lavender bag, 4 shiny blue bags.
|
||||
plaid salmon bags contain 2 faded coral bags.
|
||||
dark orange bags contain 3 light purple bags, 5 wavy blue bags, 2 muted crimson bags, 2 dull magenta bags.
|
||||
wavy beige bags contain 1 muted silver bag, 5 bright yellow bags.
|
||||
plaid cyan bags contain 4 dark orange bags, 5 dark plum bags, 5 dotted tomato bags, 5 striped magenta bags.
|
||||
dark lavender bags contain 2 mirrored beige bags, 1 pale blue bag, 2 dull chartreuse bags, 5 mirrored black bags.
|
||||
light black bags contain 1 dull tomato bag, 5 bright violet bags.
|
||||
wavy silver bags contain 2 clear gold bags.
|
||||
wavy maroon bags contain 2 posh tomato bags, 5 shiny maroon bags, 1 wavy yellow bag.
|
||||
clear lavender bags contain 1 muted white bag, 5 striped chartreuse bags, 3 dark salmon bags, 1 plaid teal bag.
|
||||
dotted brown bags contain 4 striped blue bags, 3 mirrored fuchsia bags, 3 posh red bags.
|
||||
faded teal bags contain 4 plaid olive bags.
|
||||
clear gray bags contain 2 mirrored fuchsia bags, 4 faded blue bags.
|
||||
light tomato bags contain 5 wavy indigo bags, 2 posh beige bags.
|
||||
muted black bags contain 1 dark lime bag, 1 striped green bag.
|
||||
dotted beige bags contain 5 faded lavender bags, 3 plaid yellow bags.
|
||||
posh turquoise bags contain 1 wavy indigo bag.
|
||||
bright crimson bags contain 1 dark fuchsia bag.
|
||||
striped teal bags contain 3 vibrant olive bags, 1 bright maroon bag, 3 muted teal bags, 4 clear yellow bags.
|
||||
clear orange bags contain 3 shiny plum bags, 3 drab olive bags.
|
||||
posh silver bags contain 5 mirrored violet bags, 2 dotted teal bags.
|
||||
dim gray bags contain 4 pale teal bags, 5 muted salmon bags, 3 dark indigo bags.
|
||||
dotted tomato bags contain 3 dotted maroon bags.
|
||||
posh purple bags contain 3 drab turquoise bags, 3 dark olive bags, 4 posh lime bags, 1 posh orange bag.
|
||||
vibrant beige bags contain 2 mirrored violet bags, 1 mirrored white bag, 1 wavy violet bag.
|
||||
dark tan bags contain 5 bright violet bags, 5 light blue bags, 4 shiny plum bags, 1 light indigo bag.
|
||||
dim lavender bags contain 3 mirrored green bags, 1 wavy tan bag, 2 striped crimson bags, 5 wavy violet bags.
|
||||
faded crimson bags contain 3 muted yellow bags, 2 posh lime bags, 5 mirrored gray bags, 3 faded chartreuse bags.
|
||||
posh coral bags contain 3 muted silver bags, 4 pale magenta bags, 1 light orange bag.
|
||||
dull tomato bags contain 2 plaid tomato bags, 2 dim lavender bags, 4 mirrored orange bags, 3 clear fuchsia bags.
|
||||
striped orange bags contain 2 vibrant teal bags, 1 dotted teal bag.
|
||||
shiny maroon bags contain 5 light beige bags, 1 dim lime bag.
|
||||
pale olive bags contain 2 mirrored gold bags, 4 plaid tomato bags.
|
||||
light olive bags contain 1 light red bag, 1 light crimson bag, 2 striped chartreuse bags.
|
||||
posh plum bags contain 5 bright silver bags, 4 vibrant indigo bags, 4 pale turquoise bags.
|
||||
shiny orange bags contain 4 dim chartreuse bags, 2 dotted lavender bags, 2 shiny green bags.
|
||||
pale indigo bags contain 3 mirrored chartreuse bags, 5 mirrored violet bags, 2 vibrant blue bags, 3 mirrored maroon bags.
|
||||
posh tan bags contain 5 shiny plum bags, 2 dark aqua bags.
|
||||
bright blue bags contain 5 vibrant salmon bags, 5 bright maroon bags, 1 muted yellow bag.
|
||||
clear maroon bags contain 4 vibrant beige bags, 3 mirrored gold bags, 2 drab teal bags, 2 drab plum bags.
|
||||
wavy chartreuse bags contain 3 clear olive bags, 1 drab lavender bag.
|
||||
drab gray bags contain 5 plaid salmon bags.
|
||||
faded orange bags contain 1 faded maroon bag, 5 vibrant orange bags.
|
||||
bright coral bags contain 3 pale turquoise bags.
|
||||
light beige bags contain 1 muted cyan bag.
|
||||
plaid maroon bags contain 5 faded magenta bags, 4 faded bronze bags.
|
||||
dotted purple bags contain 1 drab plum bag, 5 faded black bags, 2 dull silver bags.
|
||||
muted salmon bags contain no other bags.
|
||||
striped blue bags contain 5 mirrored lime bags, 2 dark plum bags.
|
||||
dotted lavender bags contain 2 faded salmon bags, 3 dim silver bags, 1 clear cyan bag, 4 plaid lavender bags.
|
||||
wavy black bags contain 4 vibrant gold bags, 5 light black bags, 4 muted aqua bags, 5 vibrant white bags.
|
||||
clear aqua bags contain 3 plaid beige bags, 1 plaid white bag, 3 shiny red bags, 3 wavy crimson bags.
|
||||
mirrored cyan bags contain no other bags.
|
||||
shiny brown bags contain 2 dim aqua bags.
|
||||
dotted green bags contain 4 mirrored green bags, 3 mirrored tomato bags, 5 plaid gray bags.
|
||||
striped purple bags contain 3 wavy yellow bags, 2 faded orange bags.
|
||||
plaid indigo bags contain 2 shiny plum bags, 5 bright magenta bags, 2 posh yellow bags, 3 shiny gold bags.
|
||||
posh chartreuse bags contain 2 mirrored cyan bags, 4 drab salmon bags, 4 dim olive bags, 2 posh lime bags.
|
||||
light lavender bags contain 4 dim fuchsia bags, 5 pale salmon bags, 4 clear teal bags.
|
||||
shiny crimson bags contain 5 light blue bags.
|
||||
plaid black bags contain 5 clear indigo bags, 5 mirrored purple bags, 1 light aqua bag.
|
||||
shiny lime bags contain 5 dotted blue bags, 2 shiny tan bags.
|
||||
dotted salmon bags contain 4 pale salmon bags, 1 clear maroon bag.
|
||||
vibrant lavender bags contain 4 shiny red bags, 4 shiny green bags, 5 dim silver bags.
|
||||
muted yellow bags contain 5 wavy aqua bags, 2 posh lavender bags, 3 dull magenta bags, 1 plaid red bag.
|
||||
faded beige bags contain 1 wavy violet bag, 4 plaid maroon bags.
|
||||
wavy blue bags contain 5 dotted orange bags, 1 faded chartreuse bag, 4 posh magenta bags.
|
||||
faded brown bags contain 4 bright coral bags, 3 mirrored aqua bags.
|
||||
striped lavender bags contain 5 dim brown bags, 2 wavy cyan bags, 4 pale blue bags, 1 posh olive bag.
|
||||
bright fuchsia bags contain 5 clear lime bags.
|
||||
bright black bags contain 5 clear fuchsia bags, 4 pale purple bags.
|
||||
pale orange bags contain 3 plaid aqua bags, 5 muted fuchsia bags, 1 wavy crimson bag.
|
||||
mirrored magenta bags contain 2 posh chartreuse bags, 2 muted white bags, 5 posh lime bags, 5 dark gold bags.
|
||||
light magenta bags contain 1 mirrored white bag, 1 dull silver bag, 5 posh chartreuse bags.
|
||||
striped gold bags contain 1 mirrored cyan bag, 1 dark olive bag, 4 mirrored red bags, 5 posh chartreuse bags.
|
||||
plaid lavender bags contain 1 vibrant white bag, 4 dotted maroon bags.
|
||||
faded gold bags contain 5 striped crimson bags.
|
||||
vibrant olive bags contain 1 plaid beige bag.
|
||||
dark aqua bags contain 4 plaid tomato bags, 1 striped olive bag, 4 pale fuchsia bags, 3 dim gold bags.
|
||||
dim lime bags contain 2 plaid gray bags.
|
||||
pale lavender bags contain 4 muted yellow bags, 1 drab yellow bag, 2 dull cyan bags, 2 muted teal bags.
|
||||
bright violet bags contain 2 posh lime bags, 1 wavy violet bag, 2 mirrored red bags.
|
||||
dotted maroon bags contain 1 drab salmon bag.
|
||||
clear magenta bags contain 3 mirrored brown bags.
|
||||
vibrant red bags contain 5 clear cyan bags, 2 dark teal bags.
|
||||
shiny olive bags contain 5 light tan bags, 5 plaid maroon bags, 3 mirrored blue bags.
|
||||
plaid fuchsia bags contain 5 posh silver bags.
|
||||
vibrant chartreuse bags contain 2 clear coral bags, 2 pale purple bags, 5 light beige bags.
|
||||
vibrant violet bags contain 3 striped bronze bags, 2 drab tomato bags, 2 faded violet bags, 5 posh crimson bags.
|
||||
vibrant white bags contain 1 plaid orange bag, 5 muted aqua bags, 5 pale fuchsia bags, 3 muted fuchsia bags.
|
||||
drab magenta bags contain 3 bright indigo bags, 1 faded violet bag.
|
||||
faded tan bags contain 3 dark crimson bags, 5 light aqua bags.
|
||||
bright salmon bags contain 3 clear plum bags, 3 striped blue bags, 5 plaid green bags.
|
||||
wavy aqua bags contain 1 clear beige bag, 5 dull magenta bags.
|
||||
muted white bags contain 5 wavy tan bags, 5 plaid silver bags, 5 striped bronze bags, 3 dull silver bags.
|
||||
mirrored gray bags contain 4 dim olive bags, 3 striped gold bags, 1 wavy tan bag, 5 striped bronze bags.
|
||||
vibrant maroon bags contain 5 clear bronze bags.
|
||||
shiny violet bags contain 2 clear salmon bags, 1 bright beige bag.
|
||||
dim bronze bags contain 2 posh brown bags, 4 vibrant indigo bags, 2 dull purple bags.
|
||||
bright bronze bags contain 1 bright maroon bag, 4 faded aqua bags, 2 pale tan bags, 3 mirrored lavender bags.
|
||||
dull blue bags contain 4 clear coral bags, 2 drab olive bags.
|
||||
posh crimson bags contain 1 muted white bag, 2 faded maroon bags, 5 plaid olive bags.
|
||||
dark olive bags contain 3 dim olive bags, 3 mirrored red bags.
|
||||
striped violet bags contain 4 wavy gold bags, 4 dotted maroon bags, 1 vibrant salmon bag.
|
||||
vibrant tomato bags contain 1 striped gold bag, 1 faded turquoise bag.
|
||||
mirrored turquoise bags contain 2 dark magenta bags, 2 clear lime bags, 3 dull turquoise bags.
|
||||
mirrored coral bags contain 4 plaid lavender bags, 4 vibrant salmon bags, 4 mirrored chartreuse bags, 3 plaid white bags.
|
||||
muted red bags contain 2 mirrored maroon bags, 4 vibrant beige bags.
|
||||
shiny salmon bags contain 2 posh black bags, 4 wavy tan bags.
|
||||
vibrant turquoise bags contain 4 clear crimson bags.
|
||||
pale maroon bags contain 4 striped crimson bags, 5 wavy indigo bags, 3 dull turquoise bags, 2 faded black bags.
|
||||
dull beige bags contain 4 dim olive bags, 3 vibrant olive bags, 1 mirrored plum bag, 3 muted white bags.
|
||||
striped tan bags contain 5 mirrored gray bags.
|
||||
dotted magenta bags contain 4 wavy olive bags, 5 mirrored magenta bags, 4 muted fuchsia bags, 2 muted gray bags.
|
||||
pale chartreuse bags contain 1 wavy crimson bag.
|
||||
dull white bags contain 1 dull tomato bag, 4 faded tomato bags, 3 shiny fuchsia bags, 4 dim beige bags.
|
||||
light cyan bags contain 3 drab plum bags, 1 wavy violet bag, 1 vibrant gold bag, 1 dotted purple bag.
|
||||
bright tomato bags contain 1 bright plum bag.
|
||||
bright olive bags contain 1 dull green bag.
|
||||
shiny tomato bags contain 3 faded red bags, 3 mirrored gold bags.
|
||||
light white bags contain 2 dotted gray bags.
|
||||
dotted bronze bags contain 3 wavy olive bags.
|
||||
drab white bags contain 4 dim fuchsia bags.
|
||||
posh indigo bags contain 2 dull salmon bags, 4 mirrored white bags.
|
||||
vibrant coral bags contain 2 faded chartreuse bags, 3 dark indigo bags, 1 wavy coral bag.
|
||||
bright purple bags contain 4 dull white bags.
|
||||
faded blue bags contain 1 striped chartreuse bag, 2 faded crimson bags.
|
||||
striped turquoise bags contain 5 dark plum bags.
|
||||
faded green bags contain 1 mirrored white bag, 1 striped magenta bag.
|
||||
dotted indigo bags contain 5 pale olive bags, 5 vibrant fuchsia bags.
|
||||
drab blue bags contain 2 faded tomato bags.
|
||||
dull lime bags contain 4 faded crimson bags, 1 striped white bag, 3 drab bronze bags.
|
||||
bright yellow bags contain 5 drab purple bags, 2 mirrored white bags, 4 faded fuchsia bags, 2 dark tomato bags.
|
||||
clear turquoise bags contain 3 muted fuchsia bags, 3 plaid purple bags, 4 posh blue bags.
|
||||
dull crimson bags contain 5 muted green bags, 3 dotted bronze bags, 2 pale gray bags.
|
||||
light maroon bags contain 5 faded indigo bags, 1 clear yellow bag.
|
||||
wavy magenta bags contain 3 bright orange bags, 2 pale lavender bags, 1 shiny blue bag, 1 plaid purple bag.
|
||||
vibrant aqua bags contain 2 vibrant silver bags.
|
||||
posh black bags contain 3 striped crimson bags.
|
||||
bright white bags contain 2 clear white bags.
|
||||
clear bronze bags contain 2 dim aqua bags, 1 mirrored indigo bag.
|
||||
vibrant yellow bags contain 2 vibrant silver bags.
|
||||
bright silver bags contain 3 clear beige bags, 3 mirrored lime bags.
|
||||
plaid magenta bags contain 5 striped gold bags, 5 posh purple bags, 2 pale brown bags.
|
||||
shiny black bags contain 2 posh beige bags, 4 posh magenta bags, 4 dim blue bags, 4 dark bronze bags.
|
||||
shiny yellow bags contain 2 wavy turquoise bags, 2 pale purple bags.
|
||||
plaid aqua bags contain 3 shiny fuchsia bags, 1 dull tomato bag, 2 light magenta bags, 3 mirrored green bags.
|
||||
wavy bronze bags contain 2 bright gold bags, 5 plaid green bags, 1 shiny violet bag, 1 faded chartreuse bag.
|
||||
mirrored purple bags contain 2 faded tomato bags, 1 dark gold bag, 4 dim aqua bags, 1 faded aqua bag.
|
||||
muted tan bags contain 3 pale teal bags, 3 drab tomato bags, 4 pale maroon bags, 1 dim cyan bag.
|
||||
plaid blue bags contain 2 muted coral bags, 5 striped maroon bags, 3 pale plum bags, 5 dotted purple bags.
|
||||
posh gray bags contain 5 muted salmon bags, 2 wavy orange bags.
|
||||
wavy orange bags contain 5 dark aqua bags.
|
||||
bright brown bags contain 3 muted yellow bags, 5 faded lavender bags, 2 drab cyan bags, 2 mirrored indigo bags.
|
||||
dark brown bags contain 3 plaid coral bags.
|
||||
bright beige bags contain 4 vibrant indigo bags, 5 bright lime bags, 5 bright magenta bags.
|
||||
clear tan bags contain 3 dark turquoise bags, 4 vibrant cyan bags.
|
||||
light brown bags contain 3 light lime bags.
|
||||
wavy red bags contain 5 wavy cyan bags, 4 plaid bronze bags, 3 dark chartreuse bags.
|
||||
faded olive bags contain 1 wavy green bag, 3 drab olive bags.
|
||||
vibrant lime bags contain 5 vibrant silver bags, 2 light silver bags.
|
||||
faded plum bags contain 3 clear lavender bags, 1 dotted lavender bag, 5 muted silver bags, 3 plaid purple bags.
|
||||
dark violet bags contain 2 vibrant beige bags, 3 light crimson bags.
|
||||
posh lime bags contain no other bags.
|
||||
dark magenta bags contain 2 muted cyan bags.
|
||||
striped white bags contain 5 light tan bags, 3 plaid orange bags, 1 dark gold bag, 4 mirrored white bags.
|
||||
dull cyan bags contain 1 muted red bag, 5 faded lavender bags, 5 plaid gold bags, 5 dark beige bags.
|
||||
mirrored white bags contain 2 dark olive bags, 4 striped bronze bags.
|
||||
light plum bags contain 3 wavy crimson bags.
|
||||
clear red bags contain 4 faded violet bags, 3 dotted tan bags, 1 pale indigo bag, 4 vibrant brown bags.
|
||||
muted maroon bags contain 3 bright indigo bags, 1 striped magenta bag.
|
||||
dull chartreuse bags contain 4 posh orange bags.
|
||||
muted green bags contain 2 vibrant orange bags, 3 dull red bags.
|
||||
muted coral bags contain 1 dark olive bag, 4 striped bronze bags.
|
||||
drab brown bags contain 3 shiny maroon bags.
|
||||
pale teal bags contain 2 faded aqua bags, 4 mirrored magenta bags, 2 plaid red bags, 1 dark coral bag.
|
||||
dull purple bags contain 2 dotted teal bags, 3 vibrant orange bags.
|
||||
mirrored maroon bags contain 3 light purple bags, 4 posh beige bags, 1 dim gold bag, 4 striped olive bags.
|
||||
dull salmon bags contain 3 mirrored red bags.
|
||||
posh maroon bags contain 3 dark bronze bags, 2 faded lavender bags, 3 plaid red bags.
|
||||
shiny teal bags contain 1 dotted purple bag, 5 dull black bags, 1 muted purple bag.
|
||||
dotted olive bags contain 1 wavy aqua bag, 2 clear indigo bags, 2 light coral bags, 1 plaid yellow bag.
|
||||
drab silver bags contain 2 wavy coral bags, 1 light purple bag, 4 shiny fuchsia bags.
|
||||
posh lavender bags contain 3 shiny plum bags, 5 wavy coral bags, 2 mirrored green bags.
|
||||
dark silver bags contain 2 vibrant blue bags, 2 dull crimson bags.
|
||||
clear indigo bags contain 3 plaid aqua bags, 4 posh orange bags.
|
||||
plaid purple bags contain 3 vibrant gold bags, 4 wavy fuchsia bags, 2 striped maroon bags, 2 wavy coral bags.
|
||||
dull gray bags contain 4 striped maroon bags, 1 striped gold bag, 4 vibrant salmon bags, 3 shiny fuchsia bags.
|
||||
dim maroon bags contain 4 shiny beige bags.
|
||||
plaid lime bags contain 4 bright lime bags, 5 vibrant tan bags.
|
||||
faded lime bags contain 3 dotted crimson bags, 2 wavy violet bags.
|
||||
pale coral bags contain 5 wavy blue bags.
|
||||
plaid crimson bags contain 2 dull black bags, 3 striped gold bags, 5 dim beige bags, 1 mirrored purple bag.
|
||||
dark beige bags contain 4 vibrant salmon bags, 2 drab plum bags, 5 dull chartreuse bags, 4 light crimson bags.
|
||||
clear crimson bags contain 2 shiny fuchsia bags, 5 faded chartreuse bags.
|
||||
dull orange bags contain 5 plaid bronze bags, 5 faded cyan bags, 3 dotted silver bags, 5 dim purple bags.
|
||||
dotted black bags contain 2 bright green bags, 5 bright tomato bags, 1 pale magenta bag.
|
||||
dull coral bags contain 2 dark beige bags, 5 striped gold bags.
|
||||
vibrant salmon bags contain 5 striped indigo bags, 2 plaid olive bags, 2 drab plum bags.
|
||||
dim blue bags contain 2 mirrored orange bags.
|
||||
dim black bags contain 2 light chartreuse bags, 1 wavy fuchsia bag.
|
||||
dark white bags contain 4 mirrored maroon bags, 2 dim lavender bags, 5 faded yellow bags, 3 dark silver bags.
|
||||
drab olive bags contain 2 muted white bags, 1 mirrored white bag, 4 striped crimson bags, 4 faded maroon bags.
|
||||
striped brown bags contain 1 dull fuchsia bag, 1 plaid crimson bag.
|
||||
clear tomato bags contain 5 drab chartreuse bags.
|
||||
muted bronze bags contain 3 light magenta bags, 4 clear yellow bags, 5 bright tomato bags.
|
||||
posh olive bags contain 3 dotted gold bags.
|
||||
dull maroon bags contain 4 plaid beige bags, 5 drab silver bags, 3 drab lime bags, 5 dull magenta bags.
|
||||
drab cyan bags contain 3 striped magenta bags, 1 vibrant bronze bag, 2 mirrored green bags, 3 plaid silver bags.
|
||||
posh magenta bags contain 1 striped chartreuse bag, 4 vibrant silver bags.
|
||||
muted violet bags contain 4 dark gold bags, 1 posh purple bag, 3 clear purple bags, 4 bright teal bags.
|
||||
muted silver bags contain 2 bright chartreuse bags, 1 clear chartreuse bag.
|
||||
wavy coral bags contain 5 mirrored red bags, 1 striped gold bag, 5 faded maroon bags, 1 dark olive bag.
|
||||
dark green bags contain 3 shiny gold bags.
|
||||
drab beige bags contain 4 vibrant crimson bags, 4 posh silver bags.
|
||||
plaid gray bags contain 2 wavy blue bags, 5 dim coral bags.
|
||||
plaid orange bags contain 3 mirrored orange bags, 1 dark olive bag, 1 light red bag, 2 striped gold bags.
|
||||
dull silver bags contain no other bags.
|
||||
shiny lavender bags contain 3 dotted yellow bags, 1 wavy indigo bag, 1 dark coral bag.
|
||||
dim brown bags contain 4 dim blue bags, 1 drab plum bag.
|
||||
posh salmon bags contain 3 dim blue bags.
|
||||
drab orange bags contain 1 faded bronze bag, 5 dull black bags.
|
||||
wavy crimson bags contain 1 drab salmon bag, 2 vibrant salmon bags.
|
||||
dull black bags contain 5 vibrant orange bags.
|
||||
clear teal bags contain 5 faded aqua bags, 1 plaid crimson bag, 1 posh silver bag.
|
||||
wavy olive bags contain 3 faded aqua bags, 3 faded fuchsia bags, 2 drab cyan bags.
|
||||
bright gray bags contain 4 clear coral bags, 2 clear white bags, 3 faded lavender bags, 4 dark turquoise bags.
|
||||
striped green bags contain 1 faded magenta bag, 1 wavy tan bag, 4 posh red bags, 1 striped bronze bag.
|
||||
clear salmon bags contain 2 striped green bags, 1 striped aqua bag, 3 muted white bags, 3 pale plum bags.
|
||||
wavy indigo bags contain 2 vibrant orange bags, 1 shiny indigo bag, 1 drab tomato bag.
|
||||
clear brown bags contain 3 muted maroon bags, 4 dotted silver bags.
|
||||
vibrant silver bags contain 4 wavy violet bags, 2 posh chartreuse bags.
|
||||
mirrored salmon bags contain 4 bright brown bags, 3 mirrored crimson bags, 1 mirrored aqua bag.
|
||||
faded white bags contain 1 wavy crimson bag, 3 drab silver bags, 5 striped yellow bags, 3 dotted olive bags.
|
||||
muted indigo bags contain 1 wavy indigo bag.
|
||||
drab aqua bags contain 5 dotted teal bags, 4 mirrored white bags.
|
||||
posh red bags contain 5 wavy crimson bags.
|
||||
dim turquoise bags contain 1 striped turquoise bag, 4 dotted crimson bags.
|
||||
dark yellow bags contain 1 drab olive bag, 3 muted aqua bags.
|
||||
pale red bags contain 2 vibrant gray bags.
|
||||
vibrant black bags contain 1 posh gray bag, 5 pale teal bags, 5 shiny red bags.
|
||||
pale purple bags contain 5 dim olive bags.
|
||||
dim tomato bags contain 3 plaid lavender bags.
|
||||
dim yellow bags contain 4 plaid brown bags.
|
||||
plaid silver bags contain no other bags.
|
||||
plaid white bags contain 2 muted purple bags, 5 dull black bags.
|
||||
muted magenta bags contain 2 plaid gray bags, 5 wavy salmon bags, 3 dark chartreuse bags.
|
||||
bright aqua bags contain 1 dark indigo bag, 1 faded gray bag, 5 vibrant white bags, 2 vibrant gold bags.
|
||||
drab crimson bags contain 2 clear orange bags.
|
||||
wavy purple bags contain 2 vibrant plum bags, 3 dark fuchsia bags, 2 pale salmon bags.
|
||||
wavy teal bags contain 1 drab salmon bag, 4 muted indigo bags, 5 bright violet bags, 5 muted bronze bags.
|
||||
pale salmon bags contain 5 mirrored blue bags, 4 mirrored maroon bags.
|
||||
faded lavender bags contain 2 muted blue bags, 4 striped blue bags, 3 pale brown bags, 2 pale purple bags.
|
||||
dull plum bags contain 5 clear coral bags.
|
||||
drab maroon bags contain 2 plaid bronze bags, 1 bright orange bag.
|
||||
light turquoise bags contain 4 striped teal bags, 4 posh indigo bags.
|
||||
dotted orange bags contain 2 wavy violet bags.
|
||||
bright teal bags contain 4 clear indigo bags, 1 vibrant violet bag.
|
||||
mirrored fuchsia bags contain 4 muted brown bags, 5 wavy coral bags, 2 wavy turquoise bags.
|
||||
dark indigo bags contain 1 light red bag, 4 vibrant lime bags, 2 drab teal bags.
|
||||
plaid brown bags contain 2 dull gray bags, 3 mirrored magenta bags.
|
||||
wavy yellow bags contain 4 dotted brown bags.
|
||||
light orange bags contain 4 shiny black bags.
|
||||
dark cyan bags contain 3 mirrored chartreuse bags, 4 pale magenta bags, 2 dull black bags, 2 posh lime bags.
|
||||
muted chartreuse bags contain 3 dull silver bags, 1 dark aqua bag, 2 light tomato bags.
|
||||
dull red bags contain 5 mirrored orange bags, 2 plaid yellow bags.
|
||||
dotted cyan bags contain 1 vibrant fuchsia bag, 5 drab olive bags, 4 clear chartreuse bags, 5 pale beige bags.
|
||||
dim beige bags contain 2 striped yellow bags, 3 bright cyan bags.
|
||||
dull magenta bags contain 4 faded black bags.
|
||||
dotted blue bags contain 2 posh maroon bags, 5 dark gold bags.
|
||||
muted olive bags contain 1 mirrored aqua bag, 4 dull black bags, 5 clear gold bags, 1 mirrored cyan bag.
|
||||
mirrored silver bags contain 2 bright blue bags, 4 shiny orange bags.
|
||||
muted brown bags contain 5 muted white bags, 4 clear violet bags, 3 light red bags.
|
||||
muted lime bags contain 2 plaid yellow bags, 2 pale chartreuse bags, 2 muted tomato bags.
|
||||
clear silver bags contain 2 clear purple bags, 2 light tomato bags, 4 light gray bags, 1 shiny crimson bag.
|
||||
dim tan bags contain 2 dull brown bags, 1 dull tomato bag, 2 dim salmon bags, 1 dull green bag.
|
||||
shiny cyan bags contain 5 plaid turquoise bags.
|
||||
faded indigo bags contain 4 drab plum bags, 4 clear maroon bags, 5 wavy cyan bags, 4 dim crimson bags.
|
||||
posh bronze bags contain 5 mirrored olive bags.
|
||||
posh aqua bags contain 3 dull violet bags, 5 bright silver bags, 1 drab coral bag, 5 shiny orange bags.
|
||||
dark blue bags contain 5 light silver bags, 1 posh magenta bag, 3 mirrored crimson bags, 4 pale chartreuse bags.
|
||||
dim crimson bags contain 1 faded gray bag, 3 dull turquoise bags.
|
||||
dark coral bags contain 3 bright violet bags, 3 mirrored violet bags.
|
||||
pale green bags contain 2 muted white bags, 5 bright lime bags, 4 dark indigo bags, 2 faded fuchsia bags.
|
||||
shiny silver bags contain 4 bright teal bags, 1 dim gold bag.
|
||||
light fuchsia bags contain 1 dull white bag, 1 striped indigo bag, 2 light orange bags.
|
||||
vibrant crimson bags contain 4 striped maroon bags, 5 dim white bags.
|
||||
clear yellow bags contain 5 bright green bags.
|
||||
striped aqua bags contain 4 mirrored beige bags, 4 clear beige bags.
|
||||
dark chartreuse bags contain 3 bright lime bags, 3 mirrored magenta bags.
|
||||
wavy turquoise bags contain 4 bright brown bags, 5 mirrored lime bags, 3 pale white bags, 3 drab salmon bags.
|
||||
faded tomato bags contain 2 clear indigo bags, 3 faded teal bags, 4 dark teal bags.
|
||||
dull indigo bags contain 5 vibrant indigo bags, 1 mirrored purple bag, 1 vibrant tan bag, 2 shiny plum bags.
|
||||
posh yellow bags contain 5 clear cyan bags, 3 mirrored red bags, 5 mirrored magenta bags.
|
||||
plaid yellow bags contain 3 vibrant gold bags, 4 posh crimson bags, 3 mirrored green bags.
|
||||
plaid olive bags contain 3 vibrant indigo bags, 3 posh indigo bags, 1 posh magenta bag, 5 dim olive bags.
|
||||
bright cyan bags contain 2 vibrant brown bags, 2 muted red bags.
|
||||
clear chartreuse bags contain 2 muted salmon bags, 1 plaid aqua bag.
|
||||
shiny plum bags contain 5 mirrored gray bags, 2 dotted maroon bags.
|
||||
dim teal bags contain 3 dotted tan bags, 4 faded aqua bags, 2 light teal bags.
|
||||
mirrored bronze bags contain 3 wavy plum bags, 5 dotted tan bags.
|
||||
muted turquoise bags contain 2 mirrored silver bags, 2 dotted yellow bags.
|
||||
clear gold bags contain 4 plaid olive bags.
|
||||
mirrored orange bags contain 5 mirrored cyan bags, 2 faded maroon bags, 2 bright violet bags.
|
||||
striped chartreuse bags contain 3 dark gold bags, 2 pale fuchsia bags.
|
||||
dull turquoise bags contain 5 faded black bags.
|
||||
bright chartreuse bags contain 1 drab turquoise bag.
|
||||
vibrant green bags contain 3 wavy plum bags, 1 shiny fuchsia bag, 3 dark yellow bags, 1 dotted lime bag.
|
||||
mirrored black bags contain 4 plaid red bags, 2 wavy brown bags.
|
||||
striped magenta bags contain 3 dim lavender bags.
|
||||
shiny gold bags contain 3 clear fuchsia bags, 2 vibrant indigo bags, 4 dotted maroon bags.
|
||||
posh fuchsia bags contain 3 dull silver bags, 3 mirrored lime bags, 2 dull black bags.
|
||||
bright magenta bags contain 5 clear violet bags, 1 light red bag, 1 mirrored white bag.
|
||||
mirrored tomato bags contain 1 dark olive bag, 5 faded maroon bags.
|
||||
wavy gray bags contain 5 dotted orange bags, 3 muted magenta bags, 2 plaid maroon bags, 4 drab tomato bags.
|
||||
dim plum bags contain 4 dim salmon bags, 4 light cyan bags, 3 wavy coral bags.
|
||||
shiny chartreuse bags contain 2 drab plum bags, 2 pale beige bags.
|
||||
striped gray bags contain 4 muted aqua bags.
|
||||
faded cyan bags contain 2 muted coral bags.
|
||||
clear coral bags contain 5 faded white bags, 5 dull coral bags.
|
||||
dim violet bags contain 2 dark tomato bags, 3 vibrant silver bags, 2 clear maroon bags.
|
||||
wavy tomato bags contain 1 striped orange bag, 2 posh magenta bags.
|
||||
drab chartreuse bags contain 4 posh crimson bags, 3 wavy brown bags.
|
||||
dotted plum bags contain 4 posh crimson bags, 3 dull magenta bags.
|
||||
striped crimson bags contain 1 wavy coral bag.
|
||||
faded yellow bags contain 2 faded gray bags.
|
||||
faded magenta bags contain 4 dotted yellow bags.
|
||||
bright orange bags contain 5 dark plum bags, 3 plaid white bags, 3 bright chartreuse bags.
|
||||
drab red bags contain 4 vibrant cyan bags.
|
||||
wavy white bags contain 4 mirrored lavender bags, 3 muted tomato bags, 3 faded tomato bags, 5 drab cyan bags.
|
||||
striped salmon bags contain 5 dotted silver bags.
|
||||
mirrored violet bags contain 3 plaid silver bags, 1 dotted maroon bag, 5 striped gray bags.
|
||||
pale fuchsia bags contain 2 dark gold bags.
|
||||
striped silver bags contain 1 faded cyan bag, 2 muted orange bags.
|
||||
dull brown bags contain 5 dotted chartreuse bags, 4 vibrant red bags, 2 plaid purple bags, 4 shiny fuchsia bags.
|
||||
dull gold bags contain 1 dull olive bag, 1 clear coral bag, 4 light tomato bags, 4 muted yellow bags.
|
||||
plaid green bags contain 5 dark bronze bags, 1 muted aqua bag, 4 plaid aqua bags.
|
||||
dim white bags contain 4 bright red bags, 2 striped teal bags, 2 posh crimson bags.
|
||||
drab salmon bags contain no other bags.
|
||||
dull fuchsia bags contain 5 clear crimson bags, 1 pale green bag, 3 vibrant coral bags, 3 plaid salmon bags.
|
||||
pale lime bags contain 1 plaid magenta bag.
|
||||
wavy lavender bags contain 4 faded magenta bags, 3 dark yellow bags, 5 plaid aqua bags.
|
||||
shiny gray bags contain 4 dark teal bags, 1 wavy crimson bag, 4 posh lime bags.
|
||||
dull bronze bags contain 5 drab tomato bags, 4 pale tan bags.
|
||||
dotted chartreuse bags contain 2 dark maroon bags, 4 mirrored black bags, 4 light orange bags.
|
||||
dotted aqua bags contain 2 mirrored maroon bags, 2 mirrored blue bags, 3 dark cyan bags, 4 dotted olive bags.
|
||||
striped indigo bags contain 4 mirrored gray bags, 5 light tan bags, 4 dotted tan bags.
|
||||
shiny magenta bags contain 5 dim chartreuse bags, 2 striped olive bags, 5 clear blue bags.
|
||||
bright lime bags contain 4 drab cyan bags, 4 striped chartreuse bags, 1 dotted yellow bag.
|
||||
dotted white bags contain 1 clear purple bag, 1 clear teal bag, 1 dotted cyan bag.
|
||||
dotted red bags contain 3 dark silver bags.
|
||||
dotted fuchsia bags contain 1 pale orange bag.
|
||||
pale aqua bags contain 1 dim beige bag, 2 shiny aqua bags, 1 faded gray bag.
|
||||
dotted tan bags contain 3 muted coral bags, 1 shiny fuchsia bag, 5 wavy tan bags.
|
||||
light bronze bags contain 1 drab lavender bag, 5 faded red bags, 3 light tan bags, 1 striped white bag.
|
||||
dim cyan bags contain 1 vibrant brown bag, 3 faded gray bags, 5 striped lime bags, 5 plaid beige bags.
|
||||
dim silver bags contain 2 striped gray bags, 3 plaid gold bags, 5 striped orange bags.
|
||||
shiny aqua bags contain 3 dotted tan bags, 4 muted brown bags, 1 mirrored maroon bag.
|
||||
drab tan bags contain 4 muted brown bags, 1 dotted lavender bag, 2 dull coral bags.
|
||||
shiny beige bags contain 2 muted blue bags, 3 wavy turquoise bags, 5 plaid silver bags.
|
||||
muted aqua bags contain 2 mirrored orange bags.
|
||||
striped beige bags contain 3 muted coral bags, 4 dim gold bags, 1 dim beige bag.
|
||||
light teal bags contain 3 faded green bags, 5 dark indigo bags, 1 pale gold bag.
|
||||
BIN
c/2020/7/main
Executable file
BIN
c/2020/7/main
Executable file
Binary file not shown.
119
c/2020/7/main.c
Normal file
119
c/2020/7/main.c
Normal file
@ -0,0 +1,119 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
#define HASH_INDEX 1024
|
||||
#define HASH_LIST_LENGTH 10
|
||||
#define NUMBER_RULES 594
|
||||
|
||||
typedef struct ValidBags {
|
||||
int hash[HASH_INDEX][HASH_LIST_LENGTH];
|
||||
int list[NUMBER_RULES];
|
||||
size_t index;
|
||||
} ValidBags;
|
||||
|
||||
bool valid_bags_contains(ValidBags *valid_bags, unsigned long h) {
|
||||
int *hash_list = valid_bags->hash[h % HASH_INDEX];
|
||||
int index = 0;
|
||||
while (hash_list[index]) {
|
||||
if (hash_list[index] == h) return true;
|
||||
index++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void valid_bags_add(ValidBags *valid_bags, unsigned long h) {
|
||||
if (!valid_bags_contains(valid_bags, h)) {
|
||||
int *hash_list = valid_bags->hash[h % HASH_INDEX];
|
||||
int index = 0;
|
||||
while (hash_list[index]) index++;
|
||||
hash_list[index] = h;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct BagQuantity {
|
||||
int number;
|
||||
unsigned long bag_name_hash;
|
||||
} BagQuantity;
|
||||
|
||||
typedef struct BagRule {
|
||||
unsigned long bag_name_hash;
|
||||
BagQuantity bag_quantities[4];
|
||||
} BagRule;
|
||||
|
||||
void print_bag_rule(BagRule *bag_rule) {
|
||||
printf("%u bags contain ", bag_rule->bag_name_hash);
|
||||
int bag_quantity_index = 0;
|
||||
BagQuantity bag_quantity = bag_rule->bag_quantities[bag_quantity_index];
|
||||
while (bag_quantity.number) {
|
||||
printf("%d %u bags, ", bag_quantity.number, bag_quantity.bag_name_hash);
|
||||
bag_quantity_index++;
|
||||
bag_quantity = bag_rule->bag_quantities[bag_quantity_index];
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void parse_bag_rule(char *bag_rule_string, BagRule *bag_rule) {
|
||||
// "light red bags contain 1 bright white bag, 2 muted yellow bags."
|
||||
char bag_name_string[30] = {0};
|
||||
char *bag_rule_token;
|
||||
|
||||
bag_rule_token = strtok(bag_rule_string, " "); // rule adjective
|
||||
strcpy(bag_name_string, bag_rule_token);
|
||||
|
||||
bag_rule_token = strtok(NULL, " "); // rule color
|
||||
strcat(bag_name_string, bag_rule_token);
|
||||
bag_rule->bag_name_hash = hash(bag_name_string);
|
||||
|
||||
strtok(NULL, " "); // "bags"
|
||||
strtok(NULL, " "); // "contain"
|
||||
|
||||
size_t bag_quantity_index = 0;
|
||||
while(bag_rule_token = strtok(NULL, " ")) { // The number is now in the buffer
|
||||
bag_rule->bag_quantities[bag_quantity_index].number = atoi(bag_rule_token);
|
||||
// printf("number: %d\n", bag_rule->bag_quantities[bag_quantity_index].number );
|
||||
|
||||
bag_rule_token = strtok(NULL, " "); // rule adjective
|
||||
strcpy(bag_name_string, bag_rule_token);
|
||||
|
||||
bag_rule_token = strtok(NULL, " "); // rule color
|
||||
strcat(bag_name_string, bag_rule_token);
|
||||
|
||||
bag_rule->bag_quantities[bag_quantity_index].bag_name_hash = hash(bag_name_string);
|
||||
strtok(NULL, " "); // "bag(s)[.,]"
|
||||
|
||||
bag_quantity_index++;
|
||||
}
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
char *data_buffer = load_input();
|
||||
char *strtok_ptr = data_buffer;
|
||||
|
||||
ValidBags valid_bags = {0};
|
||||
valid_bags_add(&valid_bags, hash("shinygold"));
|
||||
|
||||
BagRule *bag_rule = malloc(sizeof(BagRule));
|
||||
|
||||
char *rule = strtok_r(data_buffer, "\n", &strtok_ptr);
|
||||
do {
|
||||
parse_bag_rule(rule, bag_rule);
|
||||
valid_bags_add(&valid_bags, bag_rule->bag_name_hash);
|
||||
// printf("%s\n\n", rule);
|
||||
} while(rule = strtok_r(NULL, "\n", &strtok_ptr));
|
||||
printf("%d %d %d\n", valid_bags.list[0], valid_bags.list[1], valid_bags.index);
|
||||
|
||||
free(data_buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
654
c/2020/8/input.txt
Normal file
654
c/2020/8/input.txt
Normal file
@ -0,0 +1,654 @@
|
||||
acc +45
|
||||
nop +631
|
||||
acc +12
|
||||
acc -10
|
||||
jmp +127
|
||||
acc +28
|
||||
jmp +460
|
||||
jmp +619
|
||||
acc +15
|
||||
jmp +277
|
||||
nop +83
|
||||
acc +40
|
||||
acc +34
|
||||
acc +15
|
||||
jmp +108
|
||||
acc +10
|
||||
nop +61
|
||||
jmp +485
|
||||
jmp +44
|
||||
acc +3
|
||||
jmp +460
|
||||
acc +46
|
||||
acc +32
|
||||
jmp +12
|
||||
acc -1
|
||||
jmp +213
|
||||
acc +40
|
||||
acc +4
|
||||
nop +97
|
||||
acc +18
|
||||
jmp +613
|
||||
acc +15
|
||||
acc +14
|
||||
nop +374
|
||||
jmp +487
|
||||
jmp +1
|
||||
acc -1
|
||||
acc +32
|
||||
jmp +1
|
||||
jmp +418
|
||||
acc +10
|
||||
acc -9
|
||||
jmp +1
|
||||
jmp +117
|
||||
acc -5
|
||||
nop +539
|
||||
nop +456
|
||||
jmp +191
|
||||
acc +16
|
||||
jmp +431
|
||||
jmp +341
|
||||
acc -17
|
||||
acc +22
|
||||
acc +33
|
||||
acc +15
|
||||
jmp +152
|
||||
nop +277
|
||||
jmp +394
|
||||
acc -13
|
||||
acc +49
|
||||
acc -19
|
||||
jmp -26
|
||||
acc -5
|
||||
acc +13
|
||||
jmp +49
|
||||
acc +37
|
||||
acc +49
|
||||
nop +420
|
||||
acc +38
|
||||
jmp +515
|
||||
nop +168
|
||||
acc +22
|
||||
nop +151
|
||||
acc +25
|
||||
jmp +504
|
||||
acc -16
|
||||
jmp +73
|
||||
acc -6
|
||||
acc +40
|
||||
acc +9
|
||||
jmp +143
|
||||
acc +40
|
||||
acc -6
|
||||
acc +31
|
||||
nop +530
|
||||
jmp +265
|
||||
acc -13
|
||||
acc +40
|
||||
jmp +312
|
||||
acc +36
|
||||
jmp -55
|
||||
jmp +430
|
||||
jmp +551
|
||||
acc +10
|
||||
acc +18
|
||||
nop -25
|
||||
jmp +178
|
||||
acc +22
|
||||
jmp +176
|
||||
jmp +462
|
||||
acc +22
|
||||
acc +23
|
||||
acc +3
|
||||
acc +0
|
||||
jmp +162
|
||||
acc +0
|
||||
acc +27
|
||||
jmp +100
|
||||
nop +234
|
||||
acc +3
|
||||
nop +70
|
||||
nop +112
|
||||
jmp -62
|
||||
acc +8
|
||||
jmp +214
|
||||
jmp -38
|
||||
acc -15
|
||||
acc +48
|
||||
jmp +289
|
||||
nop +6
|
||||
nop +523
|
||||
jmp +286
|
||||
nop -9
|
||||
jmp +234
|
||||
jmp -74
|
||||
acc +33
|
||||
acc +14
|
||||
nop -11
|
||||
jmp -37
|
||||
acc +30
|
||||
jmp +277
|
||||
acc +35
|
||||
acc +4
|
||||
jmp +96
|
||||
acc +26
|
||||
nop +256
|
||||
acc -14
|
||||
jmp +389
|
||||
acc -19
|
||||
acc -12
|
||||
jmp +397
|
||||
jmp +477
|
||||
nop +141
|
||||
acc +21
|
||||
acc +16
|
||||
nop +29
|
||||
jmp +407
|
||||
acc +48
|
||||
jmp +243
|
||||
acc +43
|
||||
acc +41
|
||||
nop +384
|
||||
acc +24
|
||||
jmp +180
|
||||
jmp +372
|
||||
jmp +44
|
||||
acc +4
|
||||
nop +234
|
||||
acc +49
|
||||
jmp +343
|
||||
acc +0
|
||||
jmp -91
|
||||
acc -8
|
||||
acc +26
|
||||
jmp -9
|
||||
acc +37
|
||||
nop +321
|
||||
jmp +143
|
||||
jmp +278
|
||||
jmp -38
|
||||
acc +46
|
||||
nop +67
|
||||
acc +32
|
||||
jmp +445
|
||||
nop +143
|
||||
acc +35
|
||||
acc -19
|
||||
acc +33
|
||||
jmp +39
|
||||
jmp -24
|
||||
nop +393
|
||||
acc +0
|
||||
acc +36
|
||||
acc +44
|
||||
jmp -134
|
||||
acc +31
|
||||
acc +37
|
||||
acc +5
|
||||
acc -1
|
||||
jmp +291
|
||||
acc +37
|
||||
acc +36
|
||||
acc -3
|
||||
jmp -183
|
||||
acc -10
|
||||
acc +29
|
||||
acc +7
|
||||
acc +32
|
||||
jmp +205
|
||||
acc +38
|
||||
acc +20
|
||||
jmp +45
|
||||
acc +26
|
||||
acc +0
|
||||
acc +17
|
||||
acc +37
|
||||
jmp +289
|
||||
acc +20
|
||||
acc +6
|
||||
acc +18
|
||||
jmp -50
|
||||
acc +41
|
||||
acc +50
|
||||
jmp +419
|
||||
acc +20
|
||||
jmp +333
|
||||
jmp +250
|
||||
acc +35
|
||||
acc +13
|
||||
jmp -175
|
||||
acc -4
|
||||
nop +179
|
||||
jmp -57
|
||||
jmp +243
|
||||
acc -6
|
||||
acc +23
|
||||
nop -149
|
||||
jmp +1
|
||||
jmp -97
|
||||
acc -14
|
||||
acc +26
|
||||
acc +5
|
||||
nop +6
|
||||
jmp -223
|
||||
acc +12
|
||||
nop +115
|
||||
acc +38
|
||||
jmp -77
|
||||
acc +1
|
||||
acc +25
|
||||
acc +0
|
||||
jmp +276
|
||||
acc +37
|
||||
acc +31
|
||||
acc +7
|
||||
jmp +201
|
||||
acc +16
|
||||
acc +39
|
||||
acc +24
|
||||
jmp +54
|
||||
acc +45
|
||||
nop -96
|
||||
acc +17
|
||||
acc -7
|
||||
jmp +339
|
||||
acc +6
|
||||
jmp +317
|
||||
acc +12
|
||||
acc -1
|
||||
acc -4
|
||||
acc +14
|
||||
jmp +89
|
||||
acc +2
|
||||
acc +30
|
||||
jmp +60
|
||||
jmp +239
|
||||
acc +25
|
||||
acc -9
|
||||
jmp +82
|
||||
acc +45
|
||||
jmp +1
|
||||
nop +3
|
||||
jmp +1
|
||||
jmp +311
|
||||
jmp +142
|
||||
acc +36
|
||||
nop +253
|
||||
jmp +341
|
||||
acc +26
|
||||
acc +32
|
||||
acc +30
|
||||
jmp -182
|
||||
jmp +184
|
||||
jmp +331
|
||||
acc +6
|
||||
jmp -68
|
||||
nop -209
|
||||
acc +1
|
||||
acc +48
|
||||
jmp -23
|
||||
acc +11
|
||||
acc +30
|
||||
acc +45
|
||||
acc -3
|
||||
jmp -238
|
||||
jmp +1
|
||||
acc +9
|
||||
jmp +45
|
||||
acc +45
|
||||
jmp +1
|
||||
acc +44
|
||||
acc +29
|
||||
jmp -73
|
||||
acc -4
|
||||
acc +0
|
||||
acc +0
|
||||
jmp +294
|
||||
acc +35
|
||||
acc +21
|
||||
jmp +309
|
||||
nop +316
|
||||
acc -13
|
||||
jmp +1
|
||||
jmp +324
|
||||
acc -14
|
||||
acc +42
|
||||
jmp -99
|
||||
nop -103
|
||||
acc +16
|
||||
jmp -226
|
||||
nop +317
|
||||
nop +316
|
||||
acc -16
|
||||
jmp -192
|
||||
acc +33
|
||||
nop -47
|
||||
jmp -305
|
||||
jmp -81
|
||||
nop -197
|
||||
nop +249
|
||||
jmp +157
|
||||
nop -85
|
||||
jmp -246
|
||||
acc +8
|
||||
acc -14
|
||||
acc +20
|
||||
jmp -181
|
||||
acc +46
|
||||
nop +164
|
||||
acc +12
|
||||
acc -18
|
||||
jmp -199
|
||||
acc +10
|
||||
acc -9
|
||||
acc +17
|
||||
acc +15
|
||||
jmp +134
|
||||
acc -17
|
||||
acc -3
|
||||
jmp +18
|
||||
acc +35
|
||||
acc -14
|
||||
jmp +254
|
||||
acc -4
|
||||
acc +41
|
||||
acc +45
|
||||
jmp -346
|
||||
acc -18
|
||||
acc +41
|
||||
acc +48
|
||||
acc +27
|
||||
jmp -33
|
||||
acc -1
|
||||
acc -3
|
||||
acc +11
|
||||
acc -13
|
||||
jmp -224
|
||||
acc +22
|
||||
nop -73
|
||||
acc -12
|
||||
acc -18
|
||||
jmp +213
|
||||
jmp +1
|
||||
acc +39
|
||||
acc +19
|
||||
jmp +66
|
||||
jmp +126
|
||||
acc +37
|
||||
acc -17
|
||||
acc +17
|
||||
jmp -4
|
||||
acc -6
|
||||
acc +18
|
||||
acc +9
|
||||
acc -7
|
||||
jmp -195
|
||||
acc +33
|
||||
acc +24
|
||||
acc +25
|
||||
acc -19
|
||||
jmp -340
|
||||
acc +40
|
||||
acc +10
|
||||
acc +23
|
||||
jmp -308
|
||||
jmp +1
|
||||
acc +9
|
||||
jmp +1
|
||||
nop +104
|
||||
jmp +233
|
||||
jmp -24
|
||||
acc +29
|
||||
jmp -367
|
||||
acc -15
|
||||
jmp +107
|
||||
acc +12
|
||||
jmp +89
|
||||
nop -381
|
||||
jmp +1
|
||||
acc -2
|
||||
nop +233
|
||||
jmp +238
|
||||
acc +46
|
||||
acc -15
|
||||
acc +47
|
||||
jmp -290
|
||||
nop -323
|
||||
acc -9
|
||||
acc -6
|
||||
acc +0
|
||||
jmp -315
|
||||
acc +21
|
||||
nop +196
|
||||
acc +24
|
||||
acc +18
|
||||
jmp -49
|
||||
acc +21
|
||||
jmp +1
|
||||
jmp -47
|
||||
acc +49
|
||||
nop -120
|
||||
jmp -413
|
||||
acc +30
|
||||
jmp -284
|
||||
acc -17
|
||||
jmp -212
|
||||
nop +39
|
||||
nop -87
|
||||
acc -18
|
||||
jmp -122
|
||||
jmp -90
|
||||
nop +76
|
||||
jmp -277
|
||||
acc +34
|
||||
acc +49
|
||||
jmp +92
|
||||
nop +168
|
||||
acc -1
|
||||
acc +0
|
||||
jmp +26
|
||||
jmp -270
|
||||
jmp +1
|
||||
acc +14
|
||||
acc +11
|
||||
jmp +41
|
||||
acc -15
|
||||
jmp +144
|
||||
jmp +149
|
||||
acc +48
|
||||
jmp -260
|
||||
acc +27
|
||||
acc -3
|
||||
jmp +105
|
||||
acc +47
|
||||
acc -10
|
||||
jmp -316
|
||||
acc -4
|
||||
acc +41
|
||||
acc -3
|
||||
nop -289
|
||||
jmp -332
|
||||
nop -281
|
||||
nop -379
|
||||
nop +62
|
||||
jmp -456
|
||||
acc +34
|
||||
acc +23
|
||||
jmp +52
|
||||
acc +7
|
||||
jmp -374
|
||||
acc -18
|
||||
acc +45
|
||||
jmp +53
|
||||
acc +29
|
||||
nop -407
|
||||
acc +34
|
||||
jmp +9
|
||||
acc +49
|
||||
acc -1
|
||||
acc -1
|
||||
jmp +1
|
||||
jmp -55
|
||||
acc -3
|
||||
acc +5
|
||||
jmp -280
|
||||
jmp +1
|
||||
acc -13
|
||||
nop -173
|
||||
jmp -131
|
||||
acc +5
|
||||
acc +34
|
||||
jmp +105
|
||||
jmp -56
|
||||
jmp -485
|
||||
acc -14
|
||||
nop -389
|
||||
acc +13
|
||||
acc +27
|
||||
jmp -482
|
||||
nop -418
|
||||
jmp -394
|
||||
acc -9
|
||||
jmp -435
|
||||
acc -14
|
||||
nop -172
|
||||
acc +43
|
||||
jmp -159
|
||||
jmp +67
|
||||
acc +9
|
||||
acc +22
|
||||
jmp +15
|
||||
nop -405
|
||||
jmp -406
|
||||
jmp +1
|
||||
acc -19
|
||||
jmp -118
|
||||
acc +49
|
||||
jmp -385
|
||||
jmp +90
|
||||
acc -10
|
||||
jmp +10
|
||||
acc +8
|
||||
nop -315
|
||||
acc -14
|
||||
jmp -167
|
||||
jmp +49
|
||||
jmp -49
|
||||
jmp -275
|
||||
acc -1
|
||||
jmp -136
|
||||
acc +24
|
||||
acc +45
|
||||
jmp -259
|
||||
acc +2
|
||||
nop -370
|
||||
acc -18
|
||||
acc +4
|
||||
jmp -45
|
||||
acc +9
|
||||
jmp -542
|
||||
nop -39
|
||||
nop -16
|
||||
jmp +66
|
||||
acc -1
|
||||
nop -59
|
||||
acc +23
|
||||
acc -8
|
||||
jmp -91
|
||||
acc +7
|
||||
acc +37
|
||||
jmp -400
|
||||
acc +39
|
||||
jmp -162
|
||||
nop -346
|
||||
acc +5
|
||||
acc +50
|
||||
jmp -115
|
||||
jmp -141
|
||||
acc +2
|
||||
acc -18
|
||||
nop -179
|
||||
acc -19
|
||||
jmp -306
|
||||
acc -10
|
||||
acc +30
|
||||
jmp -115
|
||||
nop -47
|
||||
jmp -82
|
||||
acc +9
|
||||
acc -4
|
||||
jmp -139
|
||||
acc +18
|
||||
acc +16
|
||||
jmp -241
|
||||
jmp +1
|
||||
acc -3
|
||||
acc +11
|
||||
jmp -309
|
||||
acc +3
|
||||
acc +0
|
||||
acc +40
|
||||
jmp +1
|
||||
jmp -369
|
||||
acc +31
|
||||
jmp +1
|
||||
acc +35
|
||||
jmp -427
|
||||
acc +5
|
||||
acc -2
|
||||
jmp -26
|
||||
acc +29
|
||||
nop -121
|
||||
acc +6
|
||||
jmp -86
|
||||
nop -294
|
||||
jmp -391
|
||||
acc +50
|
||||
nop -96
|
||||
nop -325
|
||||
nop -134
|
||||
jmp -355
|
||||
acc +6
|
||||
jmp +1
|
||||
jmp -396
|
||||
nop -440
|
||||
jmp -89
|
||||
acc +22
|
||||
jmp -437
|
||||
acc +41
|
||||
acc +8
|
||||
acc +29
|
||||
jmp -603
|
||||
acc -18
|
||||
acc +16
|
||||
acc +42
|
||||
jmp -339
|
||||
acc +43
|
||||
acc -19
|
||||
nop -168
|
||||
nop -253
|
||||
jmp -198
|
||||
jmp -613
|
||||
jmp -346
|
||||
acc -4
|
||||
acc +7
|
||||
acc +40
|
||||
jmp -294
|
||||
jmp -423
|
||||
acc -4
|
||||
acc +48
|
||||
acc +41
|
||||
jmp +1
|
||||
jmp -49
|
||||
acc +4
|
||||
acc +28
|
||||
acc +9
|
||||
acc +38
|
||||
jmp -522
|
||||
jmp -5
|
||||
acc +3
|
||||
acc +6
|
||||
acc -8
|
||||
acc +44
|
||||
jmp +1
|
||||
BIN
c/2020/8/main
Executable file
BIN
c/2020/8/main
Executable file
Binary file not shown.
177
c/2020/8/main.c
Normal file
177
c/2020/8/main.c
Normal file
@ -0,0 +1,177 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../lib/util.h"
|
||||
|
||||
#define NUM_INSTRUCTIONS 654
|
||||
|
||||
typedef enum InstructionType {
|
||||
NOP,
|
||||
ACC,
|
||||
JMP
|
||||
} InstructionType;
|
||||
|
||||
typedef struct Instruction {
|
||||
InstructionType type;
|
||||
int argument;
|
||||
} Instruction;
|
||||
|
||||
typedef struct Console {
|
||||
size_t pc;
|
||||
int acc;
|
||||
Instruction program[NUM_INSTRUCTIONS];
|
||||
bool visited_instructions[NUM_INSTRUCTIONS];
|
||||
} Console;
|
||||
|
||||
void parse_instruction(char *text, Instruction *i) {
|
||||
switch (*text) {
|
||||
case 'n':
|
||||
i->type = NOP;
|
||||
break;
|
||||
case 'a':
|
||||
i->type = ACC;
|
||||
break;
|
||||
case 'j':
|
||||
i->type = JMP;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "FATAL: Illegal instruction %s\n", text);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
i->argument = atoi(text + 4);
|
||||
}
|
||||
|
||||
void console_step(Console *console) {
|
||||
Instruction i = console->program[console->pc];
|
||||
switch(i.type) {
|
||||
case NOP:
|
||||
console->pc++;
|
||||
break;
|
||||
case ACC:
|
||||
console->pc++;
|
||||
console->acc += i.argument;
|
||||
break;
|
||||
case JMP:
|
||||
console->pc += i.argument;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void console_print(Console *console) {
|
||||
printf("PC: %d, acc: %d\n", console->pc, console->acc);
|
||||
}
|
||||
|
||||
void console_reset(Console *console) {
|
||||
console->acc = 0;
|
||||
console->pc = 0;
|
||||
}
|
||||
|
||||
void console_run_until_loop(Console *console) {
|
||||
for (int i = 0; i < NUM_INSTRUCTIONS; i++) {
|
||||
console->visited_instructions[i] = false;
|
||||
}
|
||||
|
||||
while (!console->visited_instructions[console->pc]) {
|
||||
console->visited_instructions[console->pc] = true;
|
||||
console_step(console);
|
||||
}
|
||||
}
|
||||
|
||||
// true = overflow
|
||||
bool console_run_until_loop_or_overflow(Console *console) {
|
||||
for (int i = 0; i < NUM_INSTRUCTIONS; i++) {
|
||||
console->visited_instructions[i] = false;
|
||||
}
|
||||
|
||||
while (!console->visited_instructions[console->pc]) {
|
||||
console->visited_instructions[console->pc] = true;
|
||||
console_step(console);
|
||||
if (console->pc >= NUM_INSTRUCTIONS) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool console_is_current_instruction_corrupted(Console *console) {
|
||||
Instruction i = console->program[console->pc];
|
||||
printf("%d\n", i.type);
|
||||
fflush(stdout);
|
||||
switch(i.type) {
|
||||
case NOP:
|
||||
return console->pc + i.argument > NUM_INSTRUCTIONS - 7;
|
||||
case ACC:
|
||||
return false;
|
||||
case JMP:
|
||||
return console->pc == NUM_INSTRUCTIONS || console->pc == 648;
|
||||
}
|
||||
}
|
||||
|
||||
void console_run_until_corruption(Console *console) {
|
||||
int corruption_index = 0;
|
||||
for (int i = 0; i < NUM_INSTRUCTIONS; i++) {
|
||||
Instruction *inst = &(console->program[i]);
|
||||
if (inst->type == ACC) continue;
|
||||
if (inst->type == NOP) {
|
||||
inst->type = JMP;
|
||||
if (console_run_until_loop_or_overflow(console)) return;
|
||||
inst->type = NOP;
|
||||
console_reset(console);
|
||||
} else {
|
||||
inst->type = NOP;
|
||||
if (console_run_until_loop_or_overflow(console)) return;
|
||||
inst->type = JMP;
|
||||
console_reset(console);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
Console *console = malloc(sizeof(Console));
|
||||
console_reset(console);
|
||||
char *data_buffer = load_input();
|
||||
|
||||
char *instruction_text = strtok(data_buffer, "\n");
|
||||
|
||||
do {
|
||||
Instruction *inst = &(console->program[console->pc++]);
|
||||
parse_instruction(instruction_text, inst);
|
||||
} while (instruction_text = strtok(NULL, "\n"));
|
||||
|
||||
console_reset(console);
|
||||
console_run_until_loop(console);
|
||||
|
||||
int answer = console->acc;
|
||||
free(console);
|
||||
free(data_buffer);
|
||||
return answer;
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
Console *console = malloc(sizeof(Console));
|
||||
console_reset(console);
|
||||
char *data_buffer = load_input();
|
||||
|
||||
char *instruction_text = strtok(data_buffer, "\n");
|
||||
|
||||
console_reset(console);
|
||||
do {
|
||||
Instruction *inst = &(console->program[console->pc++]);
|
||||
parse_instruction(instruction_text, inst);
|
||||
} while (instruction_text = strtok(NULL, "\n"));
|
||||
|
||||
console_reset(console);
|
||||
console_run_until_corruption(console);
|
||||
|
||||
int answer = console->acc;
|
||||
free(console);
|
||||
free(data_buffer);
|
||||
return answer;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
1000
c/2020/9/input.txt
Normal file
1000
c/2020/9/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
c/2020/9/main
Executable file
BIN
c/2020/9/main
Executable file
Binary file not shown.
82
c/2020/9/main.c
Normal file
82
c/2020/9/main.c
Normal file
@ -0,0 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "../lib/util.h"
|
||||
|
||||
#define PREAMBLE_LENGTH 25
|
||||
#define MESSAGE_LENGTH 1000
|
||||
|
||||
bool has_valid_sum(unsigned long long message[MESSAGE_LENGTH], size_t index, unsigned long long number) {
|
||||
for (size_t x = index - PREAMBLE_LENGTH; x < index; x++) {
|
||||
for (size_t y = x + 1; y < index; y++) {
|
||||
if (message[x] + message[y] == number) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int part_1() {
|
||||
char *data_buffer = load_input();
|
||||
unsigned long long message[MESSAGE_LENGTH] = {0};
|
||||
size_t index = 0;
|
||||
|
||||
char *number_text = strtok(data_buffer, "\n");
|
||||
unsigned long long number;
|
||||
do {
|
||||
number = atoll(number_text);
|
||||
if (index >= PREAMBLE_LENGTH && !has_valid_sum(message, index, number)) {
|
||||
break;
|
||||
} else {
|
||||
message[index++] = number;
|
||||
}
|
||||
} while (number_text = strtok(NULL, "\n"));
|
||||
message[index] = number;
|
||||
|
||||
free(data_buffer);
|
||||
return number;
|
||||
}
|
||||
|
||||
int part_2() {
|
||||
char *data_buffer = load_input();
|
||||
unsigned long long message[MESSAGE_LENGTH] = {0};
|
||||
size_t index = 0;
|
||||
|
||||
char *number_text = strtok(data_buffer, "\n");
|
||||
unsigned long long number;
|
||||
do {
|
||||
number = atoll(number_text);
|
||||
if (index >= PREAMBLE_LENGTH && !has_valid_sum(message, index, number)) {
|
||||
break;
|
||||
} else {
|
||||
message[index++] = number;
|
||||
}
|
||||
} while (number_text = strtok(NULL, "\n"));
|
||||
message[index] = number;
|
||||
|
||||
unsigned long long sum;
|
||||
int highest, lowest;
|
||||
for (int x = 0; x < index - 1; x++) {
|
||||
sum = 0;
|
||||
highest = 0;
|
||||
lowest = number;
|
||||
bool just_right = false;
|
||||
|
||||
for (int y = x; y < index - 1; y++) {
|
||||
if (message[y] > highest) highest = message[y];
|
||||
if (message[y] < lowest) lowest = message[y];
|
||||
sum += message[y];
|
||||
if (sum >= number) break;
|
||||
}
|
||||
if (sum == number) break;
|
||||
}
|
||||
|
||||
free(data_buffer);
|
||||
return lowest + highest;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Part 1: %d\n", part_1());
|
||||
printf("Part 2: %d\n", part_2());
|
||||
}
|
||||
56
c/2020/lib/util.c
Normal file
56
c/2020/lib/util.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *load_input() {
|
||||
FILE *fp = fopen("input.txt", "r");
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
int sz = ftell(fp);
|
||||
rewind(fp);
|
||||
char *data_buffer = malloc((sz + 1) * sizeof(char));
|
||||
fread(data_buffer, sz, 1, fp);
|
||||
data_buffer[sz] = 0;
|
||||
fclose(fp);
|
||||
return data_buffer;
|
||||
}
|
||||
|
||||
InputWithSize *load_input_with_size() {
|
||||
FILE *fp = fopen("input.txt", "r");
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
int sz = ftell(fp);
|
||||
rewind(fp);
|
||||
char *data_buffer = malloc((sz + 1) * sizeof(char));
|
||||
fread(data_buffer, sz, 1, fp);
|
||||
data_buffer[sz] = 0;
|
||||
fclose(fp);
|
||||
|
||||
InputWithSize *input_with_size = malloc(sizeof(InputWithSize));
|
||||
input_with_size->size = sz + 1;
|
||||
input_with_size->data_buffer = data_buffer;
|
||||
|
||||
return input_with_size;
|
||||
}
|
||||
|
||||
void free_input_with_size(InputWithSize *input_with_size) {
|
||||
free(input_with_size -> data_buffer);
|
||||
free(input_with_size);
|
||||
}
|
||||
|
||||
void print_binary(int q) {
|
||||
char c[33] = {0};
|
||||
for (int i = 0; i < 32; i++) {
|
||||
c[i] = q & (1<<i) ? '1' : '0';
|
||||
}
|
||||
puts(c);
|
||||
}
|
||||
|
||||
// http://www.cse.yorku.ca/~oz/hash.html
|
||||
// djb2 hash
|
||||
unsigned long hash_string(unsigned char *str) {
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
|
||||
while (c = *str++)
|
||||
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
||||
|
||||
return hash;
|
||||
}
|
||||
12
c/2020/lib/util.h
Normal file
12
c/2020/lib/util.h
Normal file
@ -0,0 +1,12 @@
|
||||
typedef struct InputWithSize {
|
||||
int size;
|
||||
char *data_buffer;
|
||||
} InputWithSize;
|
||||
|
||||
#include "util.c"
|
||||
|
||||
char *load_input();
|
||||
InputWithSize *load_input_with_size();
|
||||
void free_input_with_size(InputWithSize *input_with_size);
|
||||
void print_binary(int q);
|
||||
unsigned long hash_string(unsigned char *str);
|
||||
59
ruby/2015/21/problem.rb
Normal file
59
ruby/2015/21/problem.rb
Normal file
@ -0,0 +1,59 @@
|
||||
STORE = <<-STORE
|
||||
Weapons: Cost Damage Armor
|
||||
Dagger 8 4 0
|
||||
Shortsword 10 5 0
|
||||
Warhammer 25 6 0
|
||||
Longsword 40 7 0
|
||||
Greataxe 74 8 0
|
||||
|
||||
Armor: Cost Damage Armor
|
||||
Leather 13 0 1
|
||||
Chainmail 31 0 2
|
||||
Splintmail 53 0 3
|
||||
Bandedmail 75 0 4
|
||||
Platemail 102 0 5
|
||||
|
||||
Rings: Cost Damage Armor
|
||||
Damage +1 25 1 0
|
||||
Damage +2 50 2 0
|
||||
Damage +3 100 3 0
|
||||
Defense +1 20 0 1
|
||||
Defense +2 40 0 2
|
||||
Defense +3 80 0 3
|
||||
STORE
|
||||
|
||||
WEAPON_COUNT_RANGE = [1..1]
|
||||
ARMOR_COUNT_RANGE = [0..1]
|
||||
RING_COUNT_RANGE = [0..2]
|
||||
INITIAL_HIT_POINTS = 100
|
||||
|
||||
Equipment = Struct.new(:name, :cost, :damage, :armor) do
|
||||
def + other
|
||||
Equipment.new("", cost + other.cost, damage + other.damage, armor + other.armor)
|
||||
end
|
||||
end
|
||||
|
||||
class Store
|
||||
attr_reader :type, :equipment
|
||||
def initialize(string)
|
||||
lines = string.split("\n")
|
||||
@type = lines[0].split(":")[0]
|
||||
@equipment = lines[1..].map do |line|
|
||||
chunks = line.split
|
||||
Equipment.new(chunks[0..-4].join(" "), chunks[-3].to_i, chunks[-2].to_i, chunks[-1].to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stores = STORE.split("\n\n").map{ |store| Store.new(store) }
|
||||
|
||||
WEAPON_COUNT_RANGE.map do |weapon_count|
|
||||
weapon_combinations =
|
||||
ARMOR_COUNT_RANGE.map do |armor_count|
|
||||
RING_COUNT_RANGE.map do |ring_count|
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
input = STDIN.read
|
||||
p input.split("\n\n")
|
||||
136
ruby/2016/10/problem.rb
Normal file
136
ruby/2016/10/problem.rb
Normal file
@ -0,0 +1,136 @@
|
||||
class BotFactory
|
||||
attr_reader :bots
|
||||
attr_reader :outputs
|
||||
|
||||
def initialize
|
||||
@bots = {}
|
||||
@outputs = {}
|
||||
end
|
||||
|
||||
def add_bot(bot)
|
||||
bots[bot.number] = bot
|
||||
end
|
||||
|
||||
def bot_exists?(bot_number)
|
||||
bots.key? bot_number
|
||||
end
|
||||
|
||||
def give_chip(bot_number, chip_number)
|
||||
bot = bots[bot_number]
|
||||
bot = Bot.new self, bot_number if bot.nil?
|
||||
bot.give_chip chip_number
|
||||
end
|
||||
|
||||
def take_chips(bot_number)
|
||||
bots[bot_number].take_chips
|
||||
end
|
||||
|
||||
def output_chip(output_number, chip_number)
|
||||
outputs[output_number] = [] if outputs[output_number].nil?
|
||||
outputs[output_number].push chip_number
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{bots.values.map(&:to_s).join("\n")}\n\n#{outputs}"
|
||||
end
|
||||
end
|
||||
|
||||
class Bot
|
||||
attr_reader :number, :microchips
|
||||
|
||||
def initialize(factory, number)
|
||||
@factory = factory
|
||||
@number = number
|
||||
@microchips = []
|
||||
|
||||
factory.add_bot self
|
||||
end
|
||||
|
||||
def give_chip(chip_number)
|
||||
microchips.push chip_number
|
||||
end
|
||||
|
||||
def take_chips
|
||||
chips = microchips.sort.clone
|
||||
@microchips = []
|
||||
chips
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Bot #{number} has #{microchips}"
|
||||
end
|
||||
end
|
||||
|
||||
class Command
|
||||
def self.for(string)
|
||||
(string[0] == "b" ? GiveCommand : InitCommand).for string
|
||||
end
|
||||
end
|
||||
|
||||
class GiveCommand < Command
|
||||
attr_reader :source, :low_type, :low_number, :high_type, :high_number
|
||||
def self.for(string)
|
||||
new *string.match(/bot (\d*) gives low to (\w*) (\d*) and high to (\w*) (\d*)/).captures
|
||||
end
|
||||
|
||||
def initialize(source, low_type, low_number, high_type, high_number)
|
||||
@source = source.to_i
|
||||
@low_type = low_type
|
||||
@low_number = low_number.to_i
|
||||
@high_type = high_type
|
||||
@high_number = high_number.to_i
|
||||
end
|
||||
|
||||
def init_command?
|
||||
false
|
||||
end
|
||||
|
||||
def execute(bot_factory)
|
||||
low, high = bot_factory.take_chips(source)
|
||||
give(bot_factory, low_type, low_number, low)
|
||||
give(bot_factory, high_type, high_number, high)
|
||||
end
|
||||
|
||||
def give(bot_factory, type, number, to_give)
|
||||
if type == "bot"
|
||||
bot_factory.give_chip number, to_give
|
||||
else
|
||||
bot_factory.output_chip number, to_give
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class InitCommand < Command
|
||||
def self.for(string)
|
||||
new *string.match(/value (\d*) goes to (\w*) (\d*)/).captures
|
||||
end
|
||||
|
||||
attr_reader :chip_number, :to_type, :to_number
|
||||
|
||||
def initialize(chip_number, to_type, to_number)
|
||||
@chip_number = chip_number.to_i
|
||||
@to_type = to_type
|
||||
@to_number = to_number.to_i
|
||||
end
|
||||
|
||||
def init_command?
|
||||
true
|
||||
end
|
||||
|
||||
def execute(bot_factory)
|
||||
bot_factory.give_chip to_number, chip_number
|
||||
end
|
||||
end
|
||||
|
||||
input = STDIN.read.chomp
|
||||
|
||||
command_strings = input.split "\n"
|
||||
commands = command_strings.map { |string| Command.for string }
|
||||
|
||||
init_commands, non_init_commands = commands.partition(&:init_command?)
|
||||
|
||||
bot_factory = BotFactory.new
|
||||
init_commands.each { |command| command.execute bot_factory }
|
||||
|
||||
non_init_commands.each { |command| command.execute bot_factory }
|
||||
puts bot_factory.to_s
|
||||
247
ruby/2016/11/problem.rb
Normal file
247
ruby/2016/11/problem.rb
Normal file
@ -0,0 +1,247 @@
|
||||
class Column
|
||||
attr_reader :floors, :items, :elevator, :history
|
||||
|
||||
def self.for(lines)
|
||||
floors = lines.each_with_index.map { |line, index| Floor.for line, index + 1 }
|
||||
items = floors.map(&:items).flatten
|
||||
elevator = 1
|
||||
new floors, items, elevator
|
||||
end
|
||||
|
||||
def initialize(floors, items, elevator, history=[])
|
||||
@floors = floors
|
||||
@items = items
|
||||
@elevator = elevator
|
||||
@history = history
|
||||
end
|
||||
|
||||
def to_s
|
||||
@to_s ||= floors.reverse.map do |floor|
|
||||
floor_num = "F#{floor.number}"
|
||||
elevator_indicator = elevator == floor.number ? "E " : ". "
|
||||
item_string = items.map do |item|
|
||||
floor.has_item?(item) ? item.abbr : ". "
|
||||
end.join(" ")
|
||||
"#{floor_num} #{elevator_indicator} #{item_string}"
|
||||
end.join("\n")
|
||||
end
|
||||
|
||||
def valid?
|
||||
floors.all? &:valid?
|
||||
end
|
||||
|
||||
def repeat?
|
||||
history.include? to_s
|
||||
end
|
||||
|
||||
def apply(move)
|
||||
from_floor = floors.find { |floor| move.from == floor.number }
|
||||
to_floor = floors.find { |floor| move.to == floor.number }
|
||||
other_floors = floors.find_all { |floor| ![move.from, move.to].include?(floor.number) }
|
||||
new_from_floor = Floor.new(from_floor.items - move.with, from_floor.number)
|
||||
new_to_floor = Floor.new(to_floor.items + move.with, to_floor.number)
|
||||
|
||||
self.class.new [new_from_floor, new_to_floor, *other_floors].sort_by(&:number), items, move.to, self.history + [to_s]
|
||||
end
|
||||
|
||||
def complete?
|
||||
(items - floors.last.items).empty?
|
||||
end
|
||||
|
||||
def current_floor
|
||||
floors.find { |floor| elevator == floor.number }
|
||||
end
|
||||
|
||||
def generate_moves
|
||||
current_floor.generate_moves
|
||||
end
|
||||
|
||||
def next_states
|
||||
generate_moves.map { |move| apply(move) }.select(&:valid?).reject(&:repeat?)
|
||||
end
|
||||
end
|
||||
|
||||
class Floor
|
||||
attr_reader :items, :number
|
||||
|
||||
def initialize(items, number)
|
||||
@items = items
|
||||
@number = number
|
||||
end
|
||||
|
||||
def self.for(line, number)
|
||||
strings = line.gsub(" and", "").gsub(",", "").gsub(".", "").split(" a ")[1..]
|
||||
new strings.map { |string| Item.for string }, number
|
||||
end
|
||||
|
||||
def has_item?(item)
|
||||
items.include? item
|
||||
end
|
||||
|
||||
def valid?
|
||||
items.all? { |item| item.valid_on? self }
|
||||
end
|
||||
|
||||
def generators
|
||||
items.select &:generator?
|
||||
end
|
||||
|
||||
def microchips
|
||||
items.select &:microchip?
|
||||
end
|
||||
|
||||
def has_matching_generator?(element)
|
||||
generators.any? { |gen| gen.is_element? element }
|
||||
end
|
||||
|
||||
def generate_moves
|
||||
[*one_item_moves, *two_item_moves]
|
||||
end
|
||||
|
||||
def one_item_moves
|
||||
[*one_item_up_moves, *one_item_down_moves]
|
||||
end
|
||||
|
||||
def one_item_up_moves
|
||||
return [] if number == 4
|
||||
|
||||
items.map do |item|
|
||||
Move.new number, number + 1, [item]
|
||||
end
|
||||
end
|
||||
|
||||
def one_item_down_moves
|
||||
return [] if number == 1
|
||||
|
||||
items.map do |item|
|
||||
Move.new number, number - 1, [item]
|
||||
end
|
||||
end
|
||||
|
||||
def two_item_moves
|
||||
[*two_item_up_moves, *two_item_down_moves]
|
||||
end
|
||||
|
||||
def two_item_up_moves
|
||||
return [] if number == 4
|
||||
|
||||
items.each_with_index.map do |item_one, i1|
|
||||
items.each_with_index.map do |item_two, i2|
|
||||
next if item_one == item_two
|
||||
next if i1 < i2
|
||||
Move.new number, number + 1, [item_one, item_two]
|
||||
end
|
||||
end.flatten.compact
|
||||
end
|
||||
|
||||
def two_item_down_moves
|
||||
return [] if number == 1
|
||||
|
||||
items.each_with_index.map do |item_one, i1|
|
||||
items.each_with_index.map do |item_two, i2|
|
||||
next if item_one == item_two
|
||||
next if i1 < i2
|
||||
Move.new number, number - 1, [item_one, item_two]
|
||||
end
|
||||
end.flatten.compact
|
||||
end
|
||||
end
|
||||
|
||||
class Item
|
||||
attr_reader :element
|
||||
|
||||
def initialize(element)
|
||||
@element = element
|
||||
end
|
||||
|
||||
def self.for(string)
|
||||
case string.split[1]
|
||||
when "microchip"
|
||||
Microchip.new string.split[0].split("-")[0]
|
||||
when "generator"
|
||||
Generator.new string.split[0]
|
||||
end
|
||||
end
|
||||
|
||||
def element_abbr
|
||||
element[0..1].upcase
|
||||
end
|
||||
|
||||
def abbr
|
||||
"#{element_abbr}#{object_abbr}"
|
||||
end
|
||||
|
||||
def generator?
|
||||
false
|
||||
end
|
||||
|
||||
def microchip?
|
||||
false
|
||||
end
|
||||
|
||||
def is_element?(other_element)
|
||||
element == other_element
|
||||
end
|
||||
end
|
||||
|
||||
class Microchip < Item
|
||||
def object_abbr
|
||||
"M"
|
||||
end
|
||||
|
||||
def valid_on?(floor)
|
||||
floor.has_matching_generator?(element) || floor.generators.empty?
|
||||
end
|
||||
|
||||
def microchip?
|
||||
true
|
||||
end
|
||||
|
||||
def to_s
|
||||
@to_s ||= "#{element} microchip"
|
||||
end
|
||||
end
|
||||
|
||||
class Generator < Item
|
||||
def object_abbr
|
||||
"G"
|
||||
end
|
||||
|
||||
def valid_on?(_)
|
||||
true
|
||||
end
|
||||
|
||||
def generator?
|
||||
true
|
||||
end
|
||||
|
||||
def to_s
|
||||
@to_s ||= "#{element} generator"
|
||||
end
|
||||
end
|
||||
|
||||
class Move
|
||||
attr_reader :from, :to, :with
|
||||
|
||||
def initialize(from, to, with)
|
||||
@from = from
|
||||
@to = to
|
||||
@with = with
|
||||
end
|
||||
|
||||
def to_s
|
||||
"From #{from} to #{to} with #{with.map(&:to_s)}"
|
||||
end
|
||||
end
|
||||
|
||||
input = STDIN.read.chomp
|
||||
lines = input.split("\n")
|
||||
column = Column.for(lines)
|
||||
|
||||
states = [column]
|
||||
until states.any?(&:complete?)
|
||||
states = states.map(&:next_states).flatten.uniq(&:to_s)
|
||||
puts "next"
|
||||
end
|
||||
part_1 = states.find(&:complete?).history.count
|
||||
puts "Part 1: #{part_1}"
|
||||
78
ruby/2016/12/problem.rb
Normal file
78
ruby/2016/12/problem.rb
Normal file
@ -0,0 +1,78 @@
|
||||
class Assembunny
|
||||
attr_accessor :a, :b, :c, :d, :pc, :program
|
||||
|
||||
def initialize(program)
|
||||
@a = 0
|
||||
@b = 0
|
||||
@c = 0
|
||||
@d = 0
|
||||
@pc = 0
|
||||
@program = program
|
||||
end
|
||||
|
||||
def current_instruction
|
||||
program[pc]
|
||||
end
|
||||
|
||||
def execute_current_instruction
|
||||
execute_instruction current_instruction
|
||||
end
|
||||
|
||||
def execute_instruction(instruction)
|
||||
send("exec_#{instruction.split.first}", *instruction.split[1..])
|
||||
end
|
||||
|
||||
def increment_pc
|
||||
@pc = @pc + 1
|
||||
end
|
||||
|
||||
def exec_cpy(from, to)
|
||||
if from.to_i != 0
|
||||
send("#{to}=", from.to_i)
|
||||
else
|
||||
send("#{to}=", send("#{from}"))
|
||||
end
|
||||
increment_pc
|
||||
end
|
||||
|
||||
def exec_inc(reg)
|
||||
send("#{reg}=", send("#{reg}").to_i + 1)
|
||||
increment_pc
|
||||
end
|
||||
|
||||
def exec_dec(reg)
|
||||
send("#{reg}=", send("#{reg}").to_i - 1)
|
||||
increment_pc
|
||||
end
|
||||
|
||||
def exec_jnz(predicate, to)
|
||||
predicate = send("#{predicate}") if predicate.to_i.zero?
|
||||
if predicate.to_i.zero?
|
||||
increment_pc
|
||||
else
|
||||
@pc += to.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def halts?
|
||||
@pc >= program.length
|
||||
end
|
||||
end
|
||||
|
||||
input = STDIN.read.chomp
|
||||
instructions = input.split("\n")
|
||||
computer = Assembunny.new(instructions)
|
||||
computer.execute_current_instruction until computer.halts?
|
||||
|
||||
part_1 = computer.a
|
||||
|
||||
puts "Part 1: #{part_1}"
|
||||
|
||||
computer = Assembunny.new(instructions)
|
||||
computer.c = 1
|
||||
|
||||
computer.execute_current_instruction until computer.halts?
|
||||
|
||||
part_2 = computer.a
|
||||
|
||||
puts "Part 2: #{part_2}"
|
||||
14
ruby/2016/13/problem.rb
Normal file
14
ruby/2016/13/problem.rb
Normal file
@ -0,0 +1,14 @@
|
||||
def wall?(x, y, input)
|
||||
num = input + ((x*x) + (3*x) + (2*x*y) + y + (y*y))
|
||||
num.to_s(2).split("").map(&:to_i).reject(&:zero?).count.odd?
|
||||
end
|
||||
|
||||
input = STDIN.read.chomp.to_i
|
||||
|
||||
x = (0..80).map do |y|
|
||||
(0..80).map do |x|
|
||||
wall?(x, y, input) ? "#" : "."
|
||||
end.join("")
|
||||
end.join("\n")
|
||||
|
||||
puts x
|
||||
50
ruby/2016/9/problem.rb
Normal file
50
ruby/2016/9/problem.rb
Normal file
@ -0,0 +1,50 @@
|
||||
def decompress(string)
|
||||
decompressed = ""
|
||||
compressed = string.clone
|
||||
|
||||
until compressed.empty? do
|
||||
if compressed[0] == "("
|
||||
end_index = compressed =~ /\)/
|
||||
marker = compressed[1..(end_index - 1)]
|
||||
|
||||
num_chars, repeat = marker.split("x").map(&:to_i)
|
||||
compressed = compressed[(end_index + 1)..]
|
||||
chars = compressed[...num_chars]
|
||||
repeat.times { decompressed << chars }
|
||||
compressed = compressed[num_chars..]
|
||||
else
|
||||
decompressed << compressed[0]
|
||||
compressed = compressed[1..]
|
||||
end
|
||||
end
|
||||
|
||||
decompressed
|
||||
end
|
||||
|
||||
def decompressed_length(string)
|
||||
decompressed = 0
|
||||
compressed = string.clone
|
||||
|
||||
until compressed.empty? do
|
||||
if compressed[0] == "("
|
||||
end_index = compressed =~ /\)/
|
||||
marker = compressed[1..(end_index - 1)]
|
||||
|
||||
num_chars, repeat = marker.split("x").map(&:to_i)
|
||||
compressed = compressed[(end_index + 1)..]
|
||||
chars = compressed[...num_chars]
|
||||
repeat.times { decompressed << chars }
|
||||
compressed = compressed[num_chars..]
|
||||
else
|
||||
decompressed << compressed[0]
|
||||
compressed = compressed[1..]
|
||||
end
|
||||
end
|
||||
|
||||
decompressed
|
||||
end
|
||||
|
||||
input = STDIN.read.chomp
|
||||
part_1 = decompress(input).length
|
||||
|
||||
puts "Part 1: #{part_1}"
|
||||
37
ruby/2017/3/problem.rb
Normal file
37
ruby/2017/3/problem.rb
Normal file
@ -0,0 +1,37 @@
|
||||
class Integer
|
||||
def layer
|
||||
((Math.sqrt(self).ceil) / 2) + 1
|
||||
end
|
||||
|
||||
def layer_first_corner
|
||||
(((self - 1) * 2) - 1)**2
|
||||
end
|
||||
|
||||
def layer_length
|
||||
(self - 1) << 3
|
||||
end
|
||||
|
||||
def layer_side_length
|
||||
layer_length >> 2
|
||||
end
|
||||
|
||||
def layer_last_corner
|
||||
(self + 1).layer_first_corner
|
||||
end
|
||||
|
||||
def layer_middles
|
||||
(0..3).map { |n| layer_first_corner + (layer_side_length >> 1) * ((2 * n) + 1) }
|
||||
end
|
||||
|
||||
def layer_middles_offsets
|
||||
layer.layer_middles.map { |middle| (middle - self).abs }
|
||||
end
|
||||
|
||||
def distance
|
||||
layer + layer_middles_offsets.min - 1
|
||||
end
|
||||
end
|
||||
|
||||
n = STDIN.read.chomp.to_i
|
||||
part_1 = n.distance
|
||||
puts "Part 1: #{part_1}"
|
||||
26
ruby/2017/4/problem.rb
Normal file
26
ruby/2017/4/problem.rb
Normal file
@ -0,0 +1,26 @@
|
||||
class Passphrase
|
||||
attr_reader :words
|
||||
def initialize(words)
|
||||
@words = words
|
||||
end
|
||||
|
||||
def self.for(string)
|
||||
new string.split
|
||||
end
|
||||
|
||||
def valid?
|
||||
words.group_by{ |x| x }.values.map(&:length).none? { |group_length| group_length > 1 }
|
||||
end
|
||||
|
||||
def more_valid?
|
||||
words.map{|word| word.split("").sort.join("") }.group_by{ |x| x }.values.map(&:length).none? { |group_length| group_length > 1 }
|
||||
end
|
||||
end
|
||||
|
||||
passphrase_list = STDIN.read.chomp.split("\n").map { |line| Passphrase.for line }
|
||||
|
||||
part_1 = passphrase_list.select(&:valid?).length
|
||||
puts "Part 1: #{part_1}"
|
||||
|
||||
part_2 = passphrase_list.select(&:more_valid?).length
|
||||
puts "Part 2: #{part_2}"
|
||||
48
ruby/2017/5/problem.rb
Normal file
48
ruby/2017/5/problem.rb
Normal file
@ -0,0 +1,48 @@
|
||||
class CPU
|
||||
attr_reader :jumps, :steps
|
||||
attr_accessor :stranger_jumps
|
||||
|
||||
def initialize(jumps)
|
||||
@jumps = jumps
|
||||
@pc = 0
|
||||
@steps = 0
|
||||
end
|
||||
|
||||
def self.for(string)
|
||||
new string.split.map(&:to_i)
|
||||
end
|
||||
|
||||
def step!
|
||||
@steps += 1
|
||||
if stranger_jumps && jumps[@pc] >= 3
|
||||
jumps[@pc] -= 1
|
||||
@pc += jumps[@pc] + 1
|
||||
else
|
||||
jumps[@pc] += 1
|
||||
@pc += jumps[@pc] - 1
|
||||
end
|
||||
end
|
||||
|
||||
def run!
|
||||
step! until done_running?
|
||||
end
|
||||
|
||||
def done_running?
|
||||
@pc < 0 || @pc >= jumps.length
|
||||
end
|
||||
end
|
||||
|
||||
jump_string = STDIN.read.chomp
|
||||
|
||||
cpu = CPU.for jump_string
|
||||
cpu_2 = CPU.new cpu.jumps.clone
|
||||
cpu.run!
|
||||
|
||||
part_1 = cpu.steps
|
||||
puts "Part 1: #{part_1}"
|
||||
|
||||
cpu_2.stranger_jumps = true
|
||||
cpu_2.run!
|
||||
|
||||
part_2 = cpu_2.steps
|
||||
puts "Part 2: #{part_2}"
|
||||
46
ruby/2019/1/main.rb
Normal file
46
ruby/2019/1/main.rb
Normal file
@ -0,0 +1,46 @@
|
||||
class Module
|
||||
attr_reader :mass
|
||||
def initialize(mass)
|
||||
@mass = mass
|
||||
end
|
||||
|
||||
def fuel_required
|
||||
(mass / 3) - 2
|
||||
end
|
||||
|
||||
def self.for(string)
|
||||
new(string.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
class Modules
|
||||
attr_reader :modules
|
||||
def initialize(modules)
|
||||
@modules = modules
|
||||
end
|
||||
|
||||
def self.from_file(filename, module_type)
|
||||
new(File.read(filename).split.map{ |mass| module_type.for mass })
|
||||
end
|
||||
|
||||
def total_fuel_required
|
||||
@modules.map(&:fuel_required).sum
|
||||
end
|
||||
end
|
||||
|
||||
class HeavyFuelModule < Module
|
||||
def fuel_required
|
||||
super + Fuel.new(super).fuel_required
|
||||
end
|
||||
end
|
||||
|
||||
class Fuel < Module
|
||||
def fuel_required
|
||||
return 0 if super < 0
|
||||
|
||||
super + Fuel.new(super).fuel_required
|
||||
end
|
||||
end
|
||||
|
||||
puts "Part 1: #{Modules.from_file("../data/2019/1/input.txt", Module).total_fuel_required}"
|
||||
puts "Part 2: #{Modules.from_file("../data/2019/1/input.txt", HeavyFuelModule).total_fuel_required}"
|
||||
92
ruby/2019/2/main.rb
Normal file
92
ruby/2019/2/main.rb
Normal file
@ -0,0 +1,92 @@
|
||||
class Computer
|
||||
attr_reader :data
|
||||
def initialize(data)
|
||||
@data = data
|
||||
@program_counter = 0
|
||||
@halted = true
|
||||
end
|
||||
|
||||
def run
|
||||
@halted = false
|
||||
while !@halted
|
||||
instruction_range = data[@program_counter..(@program_counter + 3)]
|
||||
opcode = OpCode.for(self, *instruction_range)
|
||||
opcode.execute
|
||||
@program_counter += 4
|
||||
end
|
||||
end
|
||||
|
||||
def read(index)
|
||||
data[index]
|
||||
end
|
||||
|
||||
def write(index, value)
|
||||
data[index] = value
|
||||
end
|
||||
|
||||
def halt
|
||||
@halted = true
|
||||
end
|
||||
|
||||
def self.from_string(string)
|
||||
new(string.split(",").map(&:to_i))
|
||||
end
|
||||
|
||||
def self.from_file(file_path)
|
||||
from_string(File.read file_path)
|
||||
end
|
||||
end
|
||||
|
||||
class OpCode
|
||||
attr_reader :computer
|
||||
def initialize(computer)
|
||||
@computer = computer
|
||||
end
|
||||
|
||||
def self.for(computer, *args)
|
||||
case args[0]
|
||||
when 1
|
||||
OpCode1.new(computer, *args[1..])
|
||||
when 2
|
||||
OpCode2.new(computer, *args[1..])
|
||||
when 99
|
||||
OpCode99.new(computer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class OpCode1 < OpCode
|
||||
attr_reader :destination, :first_position, :second_position
|
||||
def initialize(computer, arg1, arg2, arg3)
|
||||
super(computer)
|
||||
@first_position = arg1
|
||||
@second_position = arg2
|
||||
@destination = arg3
|
||||
end
|
||||
|
||||
def value_to_write
|
||||
computer.read(first_position) + computer.read(second_position)
|
||||
end
|
||||
|
||||
def execute
|
||||
computer.write destination, value_to_write
|
||||
end
|
||||
end
|
||||
|
||||
class OpCode2 < OpCode1
|
||||
def value_to_write
|
||||
computer.read(first_position) * computer.read(second_position)
|
||||
end
|
||||
end
|
||||
|
||||
class OpCode99 < OpCode
|
||||
def execute
|
||||
computer.halt
|
||||
end
|
||||
end
|
||||
|
||||
c = Computer.from_file("../data/2019/2/input.txt")
|
||||
c.write(1, 12)
|
||||
c.write(2, 2)
|
||||
c.run
|
||||
puts "Part 1: #{c.read(0)}"
|
||||
0
ruby/2025/1/problem.rb
Normal file
0
ruby/2025/1/problem.rb
Normal file
210
rust/2022/1/problem.rs
Normal file
210
rust/2022/1/problem.rs
Normal file
@ -0,0 +1,210 @@
|
||||
extern crate aoc_2022
|
||||
use aoc_2022::{sum_lines, DailyProblem};
|
||||
use std::iter::Iterator;
|
||||
use std::str::{FromStr, Lines};
|
||||
|
||||
pub struct RucksackReorganization;
|
||||
|
||||
impl DailyProblem for RucksackReorganization {
|
||||
fn name(&self) -> &str {
|
||||
"Day 3: Rucksack Reorganization"
|
||||
}
|
||||
fn index(&self) -> u8 {
|
||||
3
|
||||
}
|
||||
fn solutions(&self, input: &str) -> (String, String) {
|
||||
(
|
||||
sum_lines(input, calculate_priority).to_string(),
|
||||
ElfGroupIter(input.lines())
|
||||
.map(|eg| eg.priority().unwrap())
|
||||
.sum::<u32>()
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_priority(line: &str) -> u32 {
|
||||
Rucksack::from_str(line).unwrap().priority().unwrap()
|
||||
}
|
||||
|
||||
struct ElfGroupIter<'a>(Lines<'a>);
|
||||
|
||||
impl Iterator for ElfGroupIter<'_> {
|
||||
type Item = ElfGroup;
|
||||
|
||||
fn next(&mut self) -> Option<ElfGroup> {
|
||||
match self.0.next() {
|
||||
Some(a) => match self.0.next() {
|
||||
Some(b) => self
|
||||
.0
|
||||
.next()
|
||||
.map(|c| ElfGroup(a.to_string(), b.to_string(), c.to_string())),
|
||||
|
||||
None => None,
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn common_chars(s1: &str, s2: &str) -> String {
|
||||
let mut chars = vec![];
|
||||
for c in s1.chars() {
|
||||
if s2.contains(&(c.to_string())) {
|
||||
chars.push(c);
|
||||
}
|
||||
}
|
||||
chars.iter().collect()
|
||||
}
|
||||
|
||||
struct ElfGroup(String, String, String);
|
||||
|
||||
impl ElfGroup {
|
||||
fn badge_letter(&self) -> Option<char> {
|
||||
let badge_candidates = common_chars(&common_chars(&self.0, &self.1), &self.2);
|
||||
match badge_candidates.len() {
|
||||
0 => None,
|
||||
_ => Some(badge_candidates.chars().next().unwrap()),
|
||||
}
|
||||
}
|
||||
fn priority(&self) -> Result<u32, String> {
|
||||
match self.badge_letter() {
|
||||
Some(letter) => letter_priority(letter),
|
||||
None => Err(format!(
|
||||
"Common letter not found in {}, {}, and {}",
|
||||
self.0, self.1, self.2
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Rucksack(String, String, String);
|
||||
|
||||
impl FromStr for Rucksack {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(input: &str) -> Result<Self, ()> {
|
||||
match input.len() % 2 == 1 {
|
||||
true => Err(()),
|
||||
false => Ok(Self(
|
||||
input.to_string(),
|
||||
input[..(input.len() / 2)].to_string(),
|
||||
input[(input.len() / 2)..].to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn letter_priority(input_char: char) -> Result<u32, String> {
|
||||
let input = input_char as u32;
|
||||
if input > 64 && input < 91 {
|
||||
Ok(input - (65 - 27))
|
||||
} else if input > 96 && input < 123 {
|
||||
Ok(input - 96)
|
||||
} else {
|
||||
Err(format!(
|
||||
"No priority for input char {}({})",
|
||||
input_char, input
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Rucksack {
|
||||
fn common_letter_between_pockets(&self) -> Option<char> {
|
||||
self.1.chars().find(|c| self.2.contains(&(c.to_string())))
|
||||
}
|
||||
|
||||
fn priority(&self) -> Result<u32, String> {
|
||||
match self.common_letter_between_pockets() {
|
||||
Some(letter) => letter_priority(letter),
|
||||
None => Err(format!(
|
||||
"Common letter not found in {} and {}",
|
||||
self.0, self.1
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
#[test]
|
||||
fn common_letter_between_pockets() {
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("vJrwpWtwJgWrhcsFMMfFFhFp")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'p'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'L'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("PmmdzqPrVvPwwTWBwg")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'P'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'v'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("ttgJtRGJQctTZtZT")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
't'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("CrZsJsPPZsGzwwsLwLmpwMDw")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
's'
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn letter_priority() {
|
||||
assert_eq!(super::letter_priority('p').unwrap(), 16);
|
||||
assert_eq!(super::letter_priority('L').unwrap(), 38);
|
||||
assert_eq!(super::letter_priority('P').unwrap(), 42);
|
||||
assert_eq!(super::letter_priority('v').unwrap(), 22);
|
||||
assert_eq!(super::letter_priority('t').unwrap(), 20);
|
||||
assert_eq!(super::letter_priority('s').unwrap(), 19);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn badge_letter() {
|
||||
assert_eq!(
|
||||
super::ElfGroup(
|
||||
"vJrwpWtwJgWrhcsFMMfFFhFp".to_string(),
|
||||
"jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL".to_string(),
|
||||
"PmmdzqPrVvPwwTWBwg".to_string()
|
||||
)
|
||||
.badge_letter()
|
||||
.unwrap(),
|
||||
'r'
|
||||
);
|
||||
assert_eq!(
|
||||
super::ElfGroup(
|
||||
"wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn".to_string(),
|
||||
"ttgJtRGJQctTZtZT".to_string(),
|
||||
"CrZsJsPPZsGzwwsLwLmpwMDw".to_string()
|
||||
)
|
||||
.badge_letter()
|
||||
.unwrap(),
|
||||
'Z'
|
||||
);
|
||||
}
|
||||
}
|
||||
209
rust/2022/1/rucksack_reorganization.rs
Normal file
209
rust/2022/1/rucksack_reorganization.rs
Normal file
@ -0,0 +1,209 @@
|
||||
use aoc_2022::{sum_lines, DailyProblem};
|
||||
use std::iter::Iterator;
|
||||
use std::str::{FromStr, Lines};
|
||||
|
||||
pub struct RucksackReorganization;
|
||||
|
||||
impl DailyProblem for RucksackReorganization {
|
||||
fn name(&self) -> &str {
|
||||
"Day 3: Rucksack Reorganization"
|
||||
}
|
||||
fn index(&self) -> u8 {
|
||||
3
|
||||
}
|
||||
fn solutions(&self, input: &str) -> (String, String) {
|
||||
(
|
||||
sum_lines(input, calculate_priority).to_string(),
|
||||
ElfGroupIter(input.lines())
|
||||
.map(|eg| eg.priority().unwrap())
|
||||
.sum::<u32>()
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_priority(line: &str) -> u32 {
|
||||
Rucksack::from_str(line).unwrap().priority().unwrap()
|
||||
}
|
||||
|
||||
struct ElfGroupIter<'a>(Lines<'a>);
|
||||
|
||||
impl Iterator for ElfGroupIter<'_> {
|
||||
type Item = ElfGroup;
|
||||
|
||||
fn next(&mut self) -> Option<ElfGroup> {
|
||||
match self.0.next() {
|
||||
Some(a) => match self.0.next() {
|
||||
Some(b) => self
|
||||
.0
|
||||
.next()
|
||||
.map(|c| ElfGroup(a.to_string(), b.to_string(), c.to_string())),
|
||||
|
||||
None => None,
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn common_chars(s1: &str, s2: &str) -> String {
|
||||
let mut chars = vec![];
|
||||
for c in s1.chars() {
|
||||
if s2.contains(&(c.to_string())) {
|
||||
chars.push(c);
|
||||
}
|
||||
}
|
||||
chars.iter().collect()
|
||||
}
|
||||
|
||||
struct ElfGroup(String, String, String);
|
||||
|
||||
impl ElfGroup {
|
||||
fn badge_letter(&self) -> Option<char> {
|
||||
let badge_candidates = common_chars(&common_chars(&self.0, &self.1), &self.2);
|
||||
match badge_candidates.len() {
|
||||
0 => None,
|
||||
_ => Some(badge_candidates.chars().next().unwrap()),
|
||||
}
|
||||
}
|
||||
fn priority(&self) -> Result<u32, String> {
|
||||
match self.badge_letter() {
|
||||
Some(letter) => letter_priority(letter),
|
||||
None => Err(format!(
|
||||
"Common letter not found in {}, {}, and {}",
|
||||
self.0, self.1, self.2
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Rucksack(String, String, String);
|
||||
|
||||
impl FromStr for Rucksack {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(input: &str) -> Result<Self, ()> {
|
||||
match input.len() % 2 == 1 {
|
||||
true => Err(()),
|
||||
false => Ok(Self(
|
||||
input.to_string(),
|
||||
input[..(input.len() / 2)].to_string(),
|
||||
input[(input.len() / 2)..].to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn letter_priority(input_char: char) -> Result<u32, String> {
|
||||
let input = input_char as u32;
|
||||
if input > 64 && input < 91 {
|
||||
Ok(input - (65 - 27))
|
||||
} else if input > 96 && input < 123 {
|
||||
Ok(input - 96)
|
||||
} else {
|
||||
Err(format!(
|
||||
"No priority for input char {}({})",
|
||||
input_char, input
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Rucksack {
|
||||
fn common_letter_between_pockets(&self) -> Option<char> {
|
||||
self.1.chars().find(|c| self.2.contains(&(c.to_string())))
|
||||
}
|
||||
|
||||
fn priority(&self) -> Result<u32, String> {
|
||||
match self.common_letter_between_pockets() {
|
||||
Some(letter) => letter_priority(letter),
|
||||
None => Err(format!(
|
||||
"Common letter not found in {} and {}",
|
||||
self.0, self.1
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
#[test]
|
||||
fn common_letter_between_pockets() {
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("vJrwpWtwJgWrhcsFMMfFFhFp")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'p'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'L'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("PmmdzqPrVvPwwTWBwg")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'P'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
'v'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("ttgJtRGJQctTZtZT")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
't'
|
||||
);
|
||||
assert_eq!(
|
||||
super::Rucksack::from_str("CrZsJsPPZsGzwwsLwLmpwMDw")
|
||||
.unwrap()
|
||||
.common_letter_between_pockets()
|
||||
.unwrap(),
|
||||
's'
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn letter_priority() {
|
||||
assert_eq!(super::letter_priority('p').unwrap(), 16);
|
||||
assert_eq!(super::letter_priority('L').unwrap(), 38);
|
||||
assert_eq!(super::letter_priority('P').unwrap(), 42);
|
||||
assert_eq!(super::letter_priority('v').unwrap(), 22);
|
||||
assert_eq!(super::letter_priority('t').unwrap(), 20);
|
||||
assert_eq!(super::letter_priority('s').unwrap(), 19);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn badge_letter() {
|
||||
assert_eq!(
|
||||
super::ElfGroup(
|
||||
"vJrwpWtwJgWrhcsFMMfFFhFp".to_string(),
|
||||
"jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL".to_string(),
|
||||
"PmmdzqPrVvPwwTWBwg".to_string()
|
||||
)
|
||||
.badge_letter()
|
||||
.unwrap(),
|
||||
'r'
|
||||
);
|
||||
assert_eq!(
|
||||
super::ElfGroup(
|
||||
"wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn".to_string(),
|
||||
"ttgJtRGJQctTZtZT".to_string(),
|
||||
"CrZsJsPPZsGzwwsLwLmpwMDw".to_string()
|
||||
)
|
||||
.badge_letter()
|
||||
.unwrap(),
|
||||
'Z'
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user