Restore aoc backup.
This commit is contained in:
parent
e55b92bb46
commit
d84e861477
31
2015/day01/answer01.c
Normal file
31
2015/day01/answer01.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
int32_t floor = 0;
|
||||
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[256];
|
||||
while (fgets(buffer, sizeof(buffer), file) != NULL) {
|
||||
uint16_t length = strlen(buffer);
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
if (buffer[i] == '(') floor++;
|
||||
else if(buffer[i] == ')') floor--;
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("Error reading from file.");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("floor: %i\n", floor);
|
||||
|
||||
return 0;
|
||||
}
|
47
2015/day01/answer02.c
Normal file
47
2015/day01/answer02.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
int32_t floor = 0;
|
||||
uint32_t pos = 0;
|
||||
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[256];
|
||||
bool breakout = false;
|
||||
while (fgets(buffer, sizeof(buffer), file) != NULL) {
|
||||
uint16_t length = strlen(buffer);
|
||||
if (breakout) break;
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
if (buffer[i] == '(') {
|
||||
floor++;
|
||||
pos++;
|
||||
}
|
||||
else if (buffer[i] == ')') {
|
||||
floor--;
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (floor == -1) {
|
||||
breakout = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("Error reading form file.");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("position: %i\n", pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1
2015/day01/input
Normal file
1
2015/day01/input
Normal file
File diff suppressed because one or more lines are too long
10
2015/day01/makefile
Normal file
10
2015/day01/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -g
|
||||
LDFLAGS =
|
||||
|
||||
answer01: answer01.c
|
||||
$(CC) answer01.c -o answer01
|
||||
|
||||
answer02: answer02.c
|
||||
$(CC) answer02.c -o answer02
|
||||
|
53
2015/day02/answer01.c
Normal file
53
2015/day02/answer01.c
Normal file
@ -0,0 +1,53 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int32_t compint(const void *a, const void *b) {
|
||||
uint16_t tmp_a = *((uint16_t *)a);
|
||||
uint16_t tmp_b = *((uint16_t *)b);
|
||||
|
||||
if (tmp_a == tmp_b) return 0;
|
||||
else if (tmp_a > tmp_b) return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: Error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t l, w, h, sa_tmp;
|
||||
uint32_t sa_cum = 0;
|
||||
int8_t buffer[256];
|
||||
while (fgets(buffer, sizeof(buffer), file) != NULL) {
|
||||
if (sscanf(buffer, "%hux%hux%hu", &l, &w, &h) != 3) {
|
||||
perror("main: Error parsing string.");
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
//calculate surface area
|
||||
sa_tmp = 2*l*w + 2*w*h + 2*l*h;
|
||||
|
||||
//calculate smallest side
|
||||
uint16_t array[3] = {l, w, h};
|
||||
uint16_t n = sizeof(array)/sizeof(array[0]);
|
||||
qsort(array, n, sizeof(array[0]), compint);
|
||||
|
||||
//calculate cumulative surface area
|
||||
sa_cum = sa_cum + sa_tmp + (array[0]*array[1]);
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: Error reading from file.");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("cumulative surface area: %u\n", sa_cum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
56
2015/day02/answer02.c
Normal file
56
2015/day02/answer02.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int32_t compint(const void *a, const void *b) {
|
||||
uint16_t tmp_a = *((uint16_t *)a);
|
||||
uint16_t tmp_b = *((uint16_t *)b);
|
||||
|
||||
if (tmp_a == tmp_b) return 0;
|
||||
else if (tmp_a > tmp_b) return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: Error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t l, w, h, sp_tmp;
|
||||
uint32_t ribbon = 0;
|
||||
int8_t buffer[256];
|
||||
while (fgets(buffer, sizeof(buffer), file) != NULL) {
|
||||
if (sscanf(buffer, "%hux%hux%hu", &l, &w, &h) != 3) {
|
||||
perror("main: Error parsing string.");
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
//calculate shortest perimeter
|
||||
uint16_t array[3] = {l, w, h};
|
||||
uint16_t n = sizeof(array)/sizeof(array[0]);
|
||||
qsort(array, n, sizeof(array[0]), compint);
|
||||
sp_tmp = 2*array[0] + 2*array[1];
|
||||
|
||||
//calculate cubic volume
|
||||
uint16_t cv = l*w*h;
|
||||
|
||||
//calculate cumulative ribbon length
|
||||
ribbon = ribbon + sp_tmp + cv;
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: Error reading from file.");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("total ribbon length: %u\n", ribbon);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
1000
2015/day02/input
Normal file
1000
2015/day02/input
Normal file
File diff suppressed because it is too large
Load Diff
10
2015/day02/makefile
Normal file
10
2015/day02/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -g
|
||||
LDFLAGS =
|
||||
|
||||
answer01: answer01.c
|
||||
$(CC) answer01.c -o answer01
|
||||
|
||||
answer02: answer02.c
|
||||
$(CC) answer02.c -o answer02
|
||||
|
70
2015/day03/answer01.c
Normal file
70
2015/day03/answer01.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "01_hashtable.c"
|
||||
|
||||
house **process_next_house(house **hash_table, uint32_t *table_size, int32_t *x, int32_t *y, uint32_t *hcount) {
|
||||
//first check to see if we need to enlarge the hash table
|
||||
if (hash(*x, *y) > *table_size - 1) {
|
||||
*table_size = *table_size * 2;
|
||||
hash_table = ht_resize(hash_table, *table_size / 2, *table_size);
|
||||
}
|
||||
|
||||
//process next house
|
||||
house *loc = ht_lookup(hash_table, *x, *y);
|
||||
if (loc == NULL) {
|
||||
(*hcount)++;
|
||||
ht_insert(hash_table, *x, *y, 1);
|
||||
} else {
|
||||
(loc->p)++;
|
||||
}
|
||||
|
||||
return hash_table;
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t table_size = 25;
|
||||
house **hash_table = ht_init(table_size);
|
||||
|
||||
int32_t x = 0;
|
||||
int32_t y = 0;
|
||||
ht_insert(hash_table, x, y, 1); //initial house at (0, 0).
|
||||
uint32_t hcount = 1;
|
||||
|
||||
int32_t c;
|
||||
while ((c = fgetc(file)) != EOF) {
|
||||
if(c == '^') {
|
||||
y++;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x, &y, &hcount);
|
||||
} else if (c == 'v') {
|
||||
y--;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x, &y, &hcount);
|
||||
} else if (c == '>') {
|
||||
x++;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x, &y, &hcount);
|
||||
} else if (c == '<') {
|
||||
x--;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x, &y, &hcount);
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: error reading from file.");
|
||||
return -1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("unique houses: %u\n", hcount);
|
||||
|
||||
for (uint32_t i = 0; i < table_size; i++) {
|
||||
free(hash_table[i]);
|
||||
}
|
||||
free(hash_table);
|
||||
return 0;
|
||||
}
|
104
2015/day03/answer02.c
Normal file
104
2015/day03/answer02.c
Normal file
@ -0,0 +1,104 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "01_hashtable.c"
|
||||
|
||||
house **process_next_house(house **hash_table, uint32_t *table_size, int32_t *x, int32_t *y, uint32_t *hcount) {
|
||||
//first check to see if we need to enlarge the hash table
|
||||
if (hash(*x, *y) > *table_size - 1) {
|
||||
*table_size = *table_size * 2;
|
||||
hash_table = ht_resize(hash_table, *table_size / 2, *table_size);
|
||||
}
|
||||
|
||||
//process next house
|
||||
house *loc = ht_lookup(hash_table, *x, *y);
|
||||
if (loc == NULL) {
|
||||
(*hcount)++;
|
||||
ht_insert(hash_table, *x, *y, 1);
|
||||
} else {
|
||||
(loc->p)++;
|
||||
}
|
||||
|
||||
return hash_table;
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t table_size = 25;
|
||||
house **hash_table = ht_init(table_size);
|
||||
|
||||
/* Santa */
|
||||
int32_t x_s = 0;
|
||||
int32_t y_s = 0;
|
||||
ht_insert(hash_table, x_s, y_s, 1); //initial house at (0, 0)
|
||||
uint32_t hcount = 1;
|
||||
|
||||
/* Robo-Santa */
|
||||
int32_t x_r = 0;
|
||||
int32_t y_r = 0;
|
||||
|
||||
enum toggle {
|
||||
santa,
|
||||
robo_santa
|
||||
};
|
||||
enum toggle turn = robo_santa;
|
||||
|
||||
int32_t c;
|
||||
while ((c = fgetc(file)) != EOF) {
|
||||
turn = turn ^ robo_santa; //toggle turn
|
||||
switch(turn) {
|
||||
case santa:
|
||||
if (c == '^') {
|
||||
y_s++;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_s, &y_s, &hcount);
|
||||
} else if (c == 'v') {
|
||||
y_s--;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_s, &y_s, &hcount);
|
||||
} else if (c == '>') {
|
||||
x_s++;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_s, &y_s, &hcount);
|
||||
} else if (c == '<') {
|
||||
x_s--;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_s, &y_s, &hcount);
|
||||
}
|
||||
break;
|
||||
case robo_santa:
|
||||
if (c == '^') {
|
||||
y_r++;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_r, &y_r, &hcount);
|
||||
} else if (c == 'v') {
|
||||
y_r--;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_r, &y_r, &hcount);
|
||||
} else if (c == '>') {
|
||||
x_r++;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_r, &y_r, &hcount);
|
||||
} else if (c == '<') {
|
||||
x_r--;
|
||||
hash_table = process_next_house(hash_table, &table_size, &x_r, &y_r, &hcount);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
perror("main: turn error.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: error reading from file.");
|
||||
return -1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("unique houses: %u\n", hcount);
|
||||
|
||||
for (uint32_t i = 0; i < table_size; i++) {
|
||||
free(hash_table[i]);
|
||||
}
|
||||
free(hash_table);
|
||||
return 0;
|
||||
}
|
1
2015/day03/input
Normal file
1
2015/day03/input
Normal file
File diff suppressed because one or more lines are too long
10
2015/day03/makefile
Normal file
10
2015/day03/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -g
|
||||
LDFLAGS =
|
||||
|
||||
1: answer01.c
|
||||
$(CC) $(CFLAGS) answer01.c -o answer01
|
||||
|
||||
2: answer02.c
|
||||
$(CC) $(CFLAGS) answer02.c -o answer02
|
||||
|
62
2015/day04/answer01.c
Normal file
62
2015/day04/answer01.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
int main() {
|
||||
size_t PUZZLE_SIZE = 8; //puzzle input is 8 characters with no ending newline character
|
||||
|
||||
//load input string
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return -1;
|
||||
}
|
||||
char input[256];
|
||||
while (fgets(input, sizeof(input), file));
|
||||
if (strlen(input) != PUZZLE_SIZE) {
|
||||
perror("main: error reading file.");
|
||||
return -1;
|
||||
}
|
||||
printf("puzzle input: %s\n", input);
|
||||
|
||||
//initialize MD5 context
|
||||
//note: ignore gcc's warnings that MD5 is depreciated
|
||||
MD5_CTX md5_context;
|
||||
uint8_t md5_hash[MD5_DIGEST_LENGTH];
|
||||
char md5_string[MD5_DIGEST_LENGTH * 2 + 1]; //32 hexadecimal digits
|
||||
//each byte needs two characters in hex, plus one for '\0'
|
||||
char *md5_string_ptr = md5_string;
|
||||
|
||||
int32_t chars_written;
|
||||
int32_t available_space;
|
||||
int32_t count = -1; //initialize count at -1 so that the first count++ sets it to 0
|
||||
|
||||
while (strncmp(md5_string, "00000", 5) != 0) {
|
||||
count++;
|
||||
chars_written = snprintf(input + PUZZLE_SIZE, sizeof(input) - strlen(input), "%i", count);
|
||||
available_space = sizeof(input) - strlen(input);
|
||||
if (chars_written >= available_space) {
|
||||
perror("main: buffer overflow.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//initialize MD5 context
|
||||
MD5_Init(&md5_context);
|
||||
|
||||
//update context with input (+ count) data
|
||||
MD5_Update(&md5_context, input, strlen(input));
|
||||
|
||||
//finalize MD5 hash
|
||||
MD5_Final(md5_hash, &md5_context);
|
||||
|
||||
for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
|
||||
md5_string_ptr += sprintf(md5_string_ptr, "%02x", md5_hash[i]);
|
||||
}
|
||||
md5_string_ptr = md5_string; //reset pointer
|
||||
}
|
||||
|
||||
printf("count %i: %s\n", count, md5_string);
|
||||
return 0;
|
||||
}
|
||||
|
62
2015/day04/answer02.c
Normal file
62
2015/day04/answer02.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
int main() {
|
||||
size_t PUZZLE_SIZE = 8; //puzzle input is 8 characters with no ending newline character
|
||||
|
||||
//load input string
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return -1;
|
||||
}
|
||||
char input[256];
|
||||
while (fgets(input, sizeof(input), file));
|
||||
if (strlen(input) != PUZZLE_SIZE) {
|
||||
perror("main: error reading file.");
|
||||
return -1;
|
||||
}
|
||||
printf("puzzle input: %s\n", input);
|
||||
|
||||
//initialize MD5 context
|
||||
//note: ignore gcc's warnings that MD5 is depreciated
|
||||
MD5_CTX md5_context;
|
||||
uint8_t md5_hash[MD5_DIGEST_LENGTH];
|
||||
char md5_string[MD5_DIGEST_LENGTH * 2 + 1]; //32 hexadecimal digits
|
||||
//each byte needs two characters in hex, plus one for '\0'
|
||||
char *md5_string_ptr = md5_string;
|
||||
|
||||
int32_t chars_written;
|
||||
int32_t available_space;
|
||||
int32_t count = -1; //initialize count at -1 so that the first count++ sets it to 0
|
||||
|
||||
while (strncmp(md5_string, "000000", 6) != 0) {
|
||||
count++;
|
||||
chars_written = snprintf(input + PUZZLE_SIZE, sizeof(input) - strlen(input), "%i", count);
|
||||
available_space = sizeof(input) - strlen(input);
|
||||
if (chars_written >= available_space) {
|
||||
perror("main: buffer overflow.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//initialize MD5 context
|
||||
MD5_Init(&md5_context);
|
||||
|
||||
//update context with input (+ count) data
|
||||
MD5_Update(&md5_context, input, strlen(input));
|
||||
|
||||
//finalize MD5 hash
|
||||
MD5_Final(md5_hash, &md5_context);
|
||||
|
||||
for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
|
||||
md5_string_ptr += sprintf(md5_string_ptr, "%02x", md5_hash[i]);
|
||||
}
|
||||
md5_string_ptr = md5_string; //reset pointer
|
||||
}
|
||||
|
||||
printf("count %i: %s\n", count, md5_string);
|
||||
return 0;
|
||||
}
|
||||
|
1
2015/day04/input
Normal file
1
2015/day04/input
Normal file
@ -0,0 +1 @@
|
||||
ckczppom
|
10
2015/day04/makefile
Normal file
10
2015/day04/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -g
|
||||
LDFLAGS = -lcrypto
|
||||
|
||||
1: answer01.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer01.c -o answer01
|
||||
|
||||
2: answer02.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer02.c -o answer02
|
||||
|
57
2015/day05/answer01.c
Normal file
57
2015/day05/answer01.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
//load input string
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//string exclusions
|
||||
char *ab = "ab";
|
||||
char *cd = "cd";
|
||||
char *pq = "pq";
|
||||
char *xy = "xy";
|
||||
|
||||
uint32_t ncount = 0;
|
||||
uint8_t double_check = 0;
|
||||
uint8_t vowel_check = 0;
|
||||
char input[256];
|
||||
while (fgets(input, sizeof(input), file) != NULL) {
|
||||
//string exclusion test
|
||||
if (strstr(input, ab) || strstr(input, cd) || strstr(input, pq) || strstr(input, xy)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//double letter test
|
||||
double_check = 0;
|
||||
for (uint8_t i = 0; i < strlen(input); i++) {
|
||||
if (input[i] == input[i+1]) {
|
||||
double_check = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//three vowel test
|
||||
vowel_check = 0;
|
||||
for (uint8_t i = 0; i < strlen(input); i++) {
|
||||
if (input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u')
|
||||
vowel_check++;
|
||||
}
|
||||
|
||||
if (double_check == 1 && vowel_check >= 3)
|
||||
ncount++;
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: error reading file.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("ncount: %i\n", ncount);
|
||||
return 0;
|
||||
}
|
||||
|
47
2015/day05/answer02.c
Normal file
47
2015/day05/answer02.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
//load input string
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t ncount = 0;
|
||||
uint8_t two_repeating_check = 0;
|
||||
uint8_t two_separated_check = 0;
|
||||
char input[256];
|
||||
while (fgets(input, sizeof(input), file) != NULL) {
|
||||
|
||||
//two letters repeating test
|
||||
two_repeating_check = 0;
|
||||
for (uint8_t i = 0; i < strlen(input) - 1; i++) {
|
||||
for (uint8_t j = i + 2; j < strlen(input) - 1; j++) {
|
||||
if (input[i] == input[j] && input[i+1] == input[j+1])
|
||||
two_repeating_check = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//two letters separated by one test
|
||||
two_separated_check = 0;
|
||||
for (uint8_t i = 0; i < strlen(input) - 1; i++) {
|
||||
if (input[i] == input[i+2])
|
||||
two_separated_check = 1;
|
||||
}
|
||||
|
||||
if (two_repeating_check && two_separated_check)
|
||||
ncount++;
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: error reading file.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("ncount: %i\n", ncount);
|
||||
return 0;
|
||||
}
|
||||
|
1000
2015/day05/input
Normal file
1000
2015/day05/input
Normal file
File diff suppressed because it is too large
Load Diff
10
2015/day05/makefile
Normal file
10
2015/day05/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -g
|
||||
LDFLAGS =
|
||||
|
||||
1: answer01.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer01.c -o answer01
|
||||
|
||||
2: answer02.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer02.c -o answer02
|
||||
|
91
2015/day06/answer01.c
Normal file
91
2015/day06/answer01.c
Normal file
@ -0,0 +1,91 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void turn_on(uint16_t grid[1000][1000], uint16_t x, uint16_t y) {
|
||||
grid[x][y] = 1;
|
||||
}
|
||||
|
||||
void turn_off(uint16_t grid[1000][1000], uint16_t x, uint16_t y) {
|
||||
grid[x][y] = 0;
|
||||
}
|
||||
|
||||
void toggle(uint16_t grid[1000][1000], uint16_t x, uint16_t y) {
|
||||
if (grid[x][y] == 0)
|
||||
grid[x][y] = 1;
|
||||
else
|
||||
grid[x][y] = 0;
|
||||
}
|
||||
|
||||
void process_instruction(char *line_buffer,
|
||||
char *delimiters,
|
||||
uint16_t grid[1000][1000],
|
||||
void (*operation)(uint16_t grid[1000][1000], uint16_t, uint16_t)) {
|
||||
uint16_t x1, x2, y1, y2;
|
||||
char *token;
|
||||
|
||||
token = strtok(NULL, delimiters);
|
||||
x1 = atoi(token);
|
||||
token = strtok(NULL, delimiters);
|
||||
y1 = atoi(token);
|
||||
token = strtok(NULL, delimiters); //ignore the word "through"
|
||||
token = strtok(NULL, delimiters);
|
||||
x2 = atoi(token);
|
||||
token = strtok(NULL, delimiters);
|
||||
y2 = atoi(token);
|
||||
|
||||
for (uint16_t i = x1; i <= x2; i++)
|
||||
for (uint16_t j = y1; j <= y2; j++)
|
||||
operation(grid, i, j);
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t grid[1000][1000] = {0};
|
||||
|
||||
char delimiters[] = " ,";
|
||||
char *token;
|
||||
char line_buffer[256];
|
||||
while (fgets(line_buffer, sizeof(line_buffer), file) != NULL) {
|
||||
token = strtok(line_buffer, delimiters);
|
||||
|
||||
if (!strcmp(token, "toggle")) {
|
||||
process_instruction(line_buffer, delimiters, grid, toggle);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(token, "turn")) {
|
||||
token = strtok(NULL, delimiters);
|
||||
if (!strcmp(token, "on")) {
|
||||
process_instruction(line_buffer, delimiters, grid, turn_on);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(token, "off")) {
|
||||
process_instruction(line_buffer, delimiters, grid, turn_off);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: Error reading from file.");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
uint32_t count = 0;
|
||||
for (uint16_t i = 0; i <= 999; i++)
|
||||
for (uint16_t j = 0; j <= 999; j++)
|
||||
if (grid[i][j] == 1)
|
||||
count++;
|
||||
|
||||
printf("count: %u\n", count);
|
||||
|
||||
return 0;
|
||||
}
|
88
2015/day06/answer02.c
Normal file
88
2015/day06/answer02.c
Normal file
@ -0,0 +1,88 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void turn_on(float grid[1000][1000], uint16_t x, uint16_t y) {
|
||||
grid[x][y] += 1;
|
||||
}
|
||||
|
||||
void turn_off(float grid[1000][1000], uint16_t x, uint16_t y) {
|
||||
if (grid[x][y] > 0)
|
||||
grid[x][y] -= 1;
|
||||
}
|
||||
|
||||
void toggle(float grid[1000][1000], uint16_t x, uint16_t y) {
|
||||
grid[x][y] += 2;
|
||||
}
|
||||
|
||||
void process_instruction(char *line_buffer,
|
||||
char *delimiters,
|
||||
float grid[1000][1000],
|
||||
void (*operation)(float grid[1000][1000], uint16_t, uint16_t)) {
|
||||
uint16_t x1, x2, y1, y2;
|
||||
char *token;
|
||||
|
||||
token = strtok(NULL, delimiters);
|
||||
x1 = atoi(token);
|
||||
token = strtok(NULL, delimiters);
|
||||
y1 = atoi(token);
|
||||
token = strtok(NULL, delimiters); //ignore the word "through"
|
||||
token = strtok(NULL, delimiters);
|
||||
x2 = atoi(token);
|
||||
token = strtok(NULL, delimiters);
|
||||
y2 = atoi(token);
|
||||
|
||||
for (uint16_t x = x1; x <= x2; x++)
|
||||
for (uint16_t y = y1; y <= y2; y++)
|
||||
operation(grid, x, y);
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
float grid[1000][1000] = {0};
|
||||
|
||||
char delimiters[] = " ,";
|
||||
char *token;
|
||||
char line_buffer[256];
|
||||
while (fgets(line_buffer, sizeof(line_buffer), file) != NULL) {
|
||||
token = strtok(line_buffer, delimiters);
|
||||
|
||||
if (!strcmp(token, "toggle")) {
|
||||
process_instruction(line_buffer, delimiters, grid, toggle);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(token, "turn")) {
|
||||
token = strtok(NULL, delimiters);
|
||||
if (!strcmp(token, "on")) {
|
||||
process_instruction(line_buffer, delimiters, grid, turn_on);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(token, "off")) {
|
||||
process_instruction(line_buffer, delimiters, grid, turn_off);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ferror(file)) {
|
||||
perror("main: Error reading from file.");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
uint32_t brightness = 0;
|
||||
for (uint16_t x = 0; x <= 999; x++)
|
||||
for (uint16_t y = 0; y <= 999; y++)
|
||||
brightness += grid[x][y];
|
||||
|
||||
printf("brightness: %u\n", brightness);
|
||||
|
||||
return 0;
|
||||
}
|
300
2015/day06/input
Normal file
300
2015/day06/input
Normal file
@ -0,0 +1,300 @@
|
||||
toggle 461,550 through 564,900
|
||||
turn off 370,39 through 425,839
|
||||
turn off 464,858 through 833,915
|
||||
turn off 812,389 through 865,874
|
||||
turn on 599,989 through 806,993
|
||||
turn on 376,415 through 768,548
|
||||
turn on 606,361 through 892,600
|
||||
turn off 448,208 through 645,684
|
||||
toggle 50,472 through 452,788
|
||||
toggle 205,417 through 703,826
|
||||
toggle 533,331 through 906,873
|
||||
toggle 857,493 through 989,970
|
||||
turn off 631,950 through 894,975
|
||||
turn off 387,19 through 720,700
|
||||
turn off 511,843 through 581,945
|
||||
toggle 514,557 through 662,883
|
||||
turn off 269,809 through 876,847
|
||||
turn off 149,517 through 716,777
|
||||
turn off 994,939 through 998,988
|
||||
toggle 467,662 through 555,957
|
||||
turn on 952,417 through 954,845
|
||||
turn on 565,226 through 944,880
|
||||
turn on 214,319 through 805,722
|
||||
toggle 532,276 through 636,847
|
||||
toggle 619,80 through 689,507
|
||||
turn on 390,706 through 884,722
|
||||
toggle 17,634 through 537,766
|
||||
toggle 706,440 through 834,441
|
||||
toggle 318,207 through 499,530
|
||||
toggle 698,185 through 830,343
|
||||
toggle 566,679 through 744,716
|
||||
toggle 347,482 through 959,482
|
||||
toggle 39,799 through 981,872
|
||||
turn on 583,543 through 846,710
|
||||
turn off 367,664 through 595,872
|
||||
turn on 805,439 through 964,995
|
||||
toggle 209,584 through 513,802
|
||||
turn off 106,497 through 266,770
|
||||
turn on 975,2 through 984,623
|
||||
turn off 316,684 through 369,876
|
||||
turn off 30,309 through 259,554
|
||||
turn off 399,680 through 861,942
|
||||
toggle 227,740 through 850,829
|
||||
turn on 386,603 through 552,879
|
||||
turn off 703,795 through 791,963
|
||||
turn off 573,803 through 996,878
|
||||
turn off 993,939 through 997,951
|
||||
turn on 809,221 through 869,723
|
||||
turn off 38,720 through 682,751
|
||||
turn off 318,732 through 720,976
|
||||
toggle 88,459 through 392,654
|
||||
turn off 865,654 through 911,956
|
||||
toggle 264,284 through 857,956
|
||||
turn off 281,776 through 610,797
|
||||
toggle 492,660 through 647,910
|
||||
turn off 879,703 through 925,981
|
||||
turn off 772,414 through 974,518
|
||||
turn on 694,41 through 755,96
|
||||
turn on 452,406 through 885,881
|
||||
turn off 107,905 through 497,910
|
||||
turn off 647,222 through 910,532
|
||||
turn on 679,40 through 845,358
|
||||
turn off 144,205 through 556,362
|
||||
turn on 871,804 through 962,878
|
||||
turn on 545,676 through 545,929
|
||||
turn off 316,716 through 413,941
|
||||
toggle 488,826 through 755,971
|
||||
toggle 957,832 through 976,992
|
||||
toggle 857,770 through 905,964
|
||||
toggle 319,198 through 787,673
|
||||
turn on 832,813 through 863,844
|
||||
turn on 818,296 through 818,681
|
||||
turn on 71,699 through 91,960
|
||||
turn off 838,578 through 967,928
|
||||
toggle 440,856 through 507,942
|
||||
toggle 121,970 through 151,974
|
||||
toggle 391,192 through 659,751
|
||||
turn on 78,210 through 681,419
|
||||
turn on 324,591 through 593,939
|
||||
toggle 159,366 through 249,760
|
||||
turn off 617,167 through 954,601
|
||||
toggle 484,607 through 733,657
|
||||
turn on 587,96 through 888,819
|
||||
turn off 680,984 through 941,991
|
||||
turn on 800,512 through 968,691
|
||||
turn off 123,588 through 853,603
|
||||
turn on 1,862 through 507,912
|
||||
turn on 699,839 through 973,878
|
||||
turn off 848,89 through 887,893
|
||||
toggle 344,353 through 462,403
|
||||
turn on 780,731 through 841,760
|
||||
toggle 693,973 through 847,984
|
||||
toggle 989,936 through 996,958
|
||||
toggle 168,475 through 206,963
|
||||
turn on 742,683 through 769,845
|
||||
toggle 768,116 through 987,396
|
||||
turn on 190,364 through 617,526
|
||||
turn off 470,266 through 530,839
|
||||
toggle 122,497 through 969,645
|
||||
turn off 492,432 through 827,790
|
||||
turn on 505,636 through 957,820
|
||||
turn on 295,476 through 698,958
|
||||
toggle 63,298 through 202,396
|
||||
turn on 157,315 through 412,939
|
||||
turn off 69,789 through 134,837
|
||||
turn off 678,335 through 896,541
|
||||
toggle 140,516 through 842,668
|
||||
turn off 697,585 through 712,668
|
||||
toggle 507,832 through 578,949
|
||||
turn on 678,279 through 886,621
|
||||
toggle 449,744 through 826,910
|
||||
turn off 835,354 through 921,741
|
||||
toggle 924,878 through 985,952
|
||||
turn on 666,503 through 922,905
|
||||
turn on 947,453 through 961,587
|
||||
toggle 525,190 through 795,654
|
||||
turn off 62,320 through 896,362
|
||||
turn on 21,458 through 972,536
|
||||
turn on 446,429 through 821,970
|
||||
toggle 376,423 through 805,455
|
||||
toggle 494,896 through 715,937
|
||||
turn on 583,270 through 667,482
|
||||
turn off 183,468 through 280,548
|
||||
toggle 623,289 through 750,524
|
||||
turn on 836,706 through 967,768
|
||||
turn on 419,569 through 912,908
|
||||
turn on 428,260 through 660,433
|
||||
turn off 683,627 through 916,816
|
||||
turn on 447,973 through 866,980
|
||||
turn on 688,607 through 938,990
|
||||
turn on 245,187 through 597,405
|
||||
turn off 558,843 through 841,942
|
||||
turn off 325,666 through 713,834
|
||||
toggle 672,606 through 814,935
|
||||
turn off 161,812 through 490,954
|
||||
turn on 950,362 through 985,898
|
||||
turn on 143,22 through 205,821
|
||||
turn on 89,762 through 607,790
|
||||
toggle 234,245 through 827,303
|
||||
turn on 65,599 through 764,997
|
||||
turn on 232,466 through 965,695
|
||||
turn on 739,122 through 975,590
|
||||
turn off 206,112 through 940,558
|
||||
toggle 690,365 through 988,552
|
||||
turn on 907,438 through 977,691
|
||||
turn off 838,809 through 944,869
|
||||
turn on 222,12 through 541,832
|
||||
toggle 337,66 through 669,812
|
||||
turn on 732,821 through 897,912
|
||||
toggle 182,862 through 638,996
|
||||
turn on 955,808 through 983,847
|
||||
toggle 346,227 through 841,696
|
||||
turn on 983,270 through 989,756
|
||||
turn off 874,849 through 876,905
|
||||
turn off 7,760 through 678,795
|
||||
toggle 973,977 through 995,983
|
||||
turn off 911,961 through 914,976
|
||||
turn on 913,557 through 952,722
|
||||
turn off 607,933 through 939,999
|
||||
turn on 226,604 through 517,622
|
||||
turn off 3,564 through 344,842
|
||||
toggle 340,578 through 428,610
|
||||
turn on 248,916 through 687,925
|
||||
toggle 650,185 through 955,965
|
||||
toggle 831,359 through 933,536
|
||||
turn off 544,614 through 896,953
|
||||
toggle 648,939 through 975,997
|
||||
turn on 464,269 through 710,521
|
||||
turn off 643,149 through 791,320
|
||||
turn off 875,549 through 972,643
|
||||
turn off 953,969 through 971,972
|
||||
turn off 236,474 through 772,591
|
||||
toggle 313,212 through 489,723
|
||||
toggle 896,829 through 897,837
|
||||
toggle 544,449 through 995,905
|
||||
turn off 278,645 through 977,876
|
||||
turn off 887,947 through 946,977
|
||||
turn on 342,861 through 725,935
|
||||
turn on 636,316 through 692,513
|
||||
toggle 857,470 through 950,528
|
||||
turn off 736,196 through 826,889
|
||||
turn on 17,878 through 850,987
|
||||
turn on 142,968 through 169,987
|
||||
turn on 46,470 through 912,853
|
||||
turn on 182,252 through 279,941
|
||||
toggle 261,143 through 969,657
|
||||
turn off 69,600 through 518,710
|
||||
turn on 372,379 through 779,386
|
||||
toggle 867,391 through 911,601
|
||||
turn off 174,287 through 900,536
|
||||
toggle 951,842 through 993,963
|
||||
turn off 626,733 through 985,827
|
||||
toggle 622,70 through 666,291
|
||||
turn off 980,671 through 985,835
|
||||
turn off 477,63 through 910,72
|
||||
turn off 779,39 through 940,142
|
||||
turn on 986,570 through 997,638
|
||||
toggle 842,805 through 943,985
|
||||
turn off 890,886 through 976,927
|
||||
turn off 893,172 through 897,619
|
||||
turn off 198,780 through 835,826
|
||||
toggle 202,209 through 219,291
|
||||
turn off 193,52 through 833,283
|
||||
toggle 414,427 through 987,972
|
||||
turn on 375,231 through 668,236
|
||||
turn off 646,598 through 869,663
|
||||
toggle 271,462 through 414,650
|
||||
turn off 679,121 through 845,467
|
||||
toggle 76,847 through 504,904
|
||||
turn off 15,617 through 509,810
|
||||
toggle 248,105 through 312,451
|
||||
turn off 126,546 through 922,879
|
||||
turn on 531,831 through 903,872
|
||||
toggle 602,431 through 892,792
|
||||
turn off 795,223 through 892,623
|
||||
toggle 167,721 through 533,929
|
||||
toggle 813,251 through 998,484
|
||||
toggle 64,640 through 752,942
|
||||
turn on 155,955 through 892,985
|
||||
turn on 251,329 through 996,497
|
||||
turn off 341,716 through 462,994
|
||||
toggle 760,127 through 829,189
|
||||
turn on 86,413 through 408,518
|
||||
toggle 340,102 through 918,558
|
||||
turn off 441,642 through 751,889
|
||||
turn on 785,292 through 845,325
|
||||
turn off 123,389 through 725,828
|
||||
turn on 905,73 through 983,270
|
||||
turn off 807,86 through 879,276
|
||||
toggle 500,866 through 864,916
|
||||
turn on 809,366 through 828,534
|
||||
toggle 219,356 through 720,617
|
||||
turn off 320,964 through 769,990
|
||||
turn off 903,167 through 936,631
|
||||
toggle 300,137 through 333,693
|
||||
toggle 5,675 through 755,848
|
||||
turn off 852,235 through 946,783
|
||||
toggle 355,556 through 941,664
|
||||
turn on 810,830 through 867,891
|
||||
turn off 509,869 through 667,903
|
||||
toggle 769,400 through 873,892
|
||||
turn on 553,614 through 810,729
|
||||
turn on 179,873 through 589,962
|
||||
turn off 466,866 through 768,926
|
||||
toggle 143,943 through 465,984
|
||||
toggle 182,380 through 569,552
|
||||
turn off 735,808 through 917,910
|
||||
turn on 731,802 through 910,847
|
||||
turn off 522,74 through 731,485
|
||||
turn on 444,127 through 566,996
|
||||
turn off 232,962 through 893,979
|
||||
turn off 231,492 through 790,976
|
||||
turn on 874,567 through 943,684
|
||||
toggle 911,840 through 990,932
|
||||
toggle 547,895 through 667,935
|
||||
turn off 93,294 through 648,636
|
||||
turn off 190,902 through 532,970
|
||||
turn off 451,530 through 704,613
|
||||
toggle 936,774 through 937,775
|
||||
turn off 116,843 through 533,934
|
||||
turn on 950,906 through 986,993
|
||||
turn on 910,51 through 945,989
|
||||
turn on 986,498 through 994,945
|
||||
turn off 125,324 through 433,704
|
||||
turn off 60,313 through 75,728
|
||||
turn on 899,494 through 940,947
|
||||
toggle 832,316 through 971,817
|
||||
toggle 994,983 through 998,984
|
||||
toggle 23,353 through 917,845
|
||||
toggle 174,799 through 658,859
|
||||
turn off 490,878 through 534,887
|
||||
turn off 623,963 through 917,975
|
||||
toggle 721,333 through 816,975
|
||||
toggle 589,687 through 890,921
|
||||
turn on 936,388 through 948,560
|
||||
turn off 485,17 through 655,610
|
||||
turn on 435,158 through 689,495
|
||||
turn on 192,934 through 734,936
|
||||
turn off 299,723 through 622,847
|
||||
toggle 484,160 through 812,942
|
||||
turn off 245,754 through 818,851
|
||||
turn on 298,419 through 824,634
|
||||
toggle 868,687 through 969,760
|
||||
toggle 131,250 through 685,426
|
||||
turn off 201,954 through 997,983
|
||||
turn on 353,910 through 832,961
|
||||
turn off 518,781 through 645,875
|
||||
turn off 866,97 through 924,784
|
||||
toggle 836,599 through 857,767
|
||||
turn on 80,957 through 776,968
|
||||
toggle 277,130 through 513,244
|
||||
turn off 62,266 through 854,434
|
||||
turn on 792,764 through 872,842
|
||||
turn off 160,949 through 273,989
|
||||
turn off 664,203 through 694,754
|
||||
toggle 491,615 through 998,836
|
||||
turn off 210,146 through 221,482
|
||||
turn off 209,780 through 572,894
|
||||
turn on 766,112 through 792,868
|
||||
turn on 222,12 through 856,241
|
10
2015/day06/makefile
Normal file
10
2015/day06/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -g
|
||||
LDFLAGS =
|
||||
|
||||
1: answer01.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer01.c -o answer01
|
||||
|
||||
2: answer02.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer02.c -o answer02
|
||||
|
175
2015/day07/answer01.c
Normal file
175
2015/day07/answer01.c
Normal file
@ -0,0 +1,175 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef enum {
|
||||
ASSIGN,
|
||||
AND,
|
||||
OR,
|
||||
LSHIFT,
|
||||
RSHIFT,
|
||||
NOT
|
||||
} Gate;
|
||||
|
||||
typedef struct {
|
||||
char l_operand[3];
|
||||
char r_operand[3];
|
||||
Gate gate;
|
||||
bool assigned;
|
||||
uint16_t value;
|
||||
} Wire;
|
||||
|
||||
/* hash: for single character strings, convert the character to its natural index.
|
||||
* for two character strings, treat the string as a base 26 number.
|
||||
* e.g., a -> 0, b -> 1, ..., z -> 25, aa -> 26, ..., etc.
|
||||
*/
|
||||
int32_t hash(char *str) {
|
||||
int32_t length = strlen(str);
|
||||
if (length == 1) {
|
||||
return str[0] - 'a';
|
||||
} else if (length == 2) {
|
||||
return 26 * ((str[0] - 'a') + 1) + (str[1] - 'a');
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// is_int: return 1 if the string argument is an integer; 0 otherwise.
|
||||
int32_t is_int(char *str) {
|
||||
while (isspace((unsigned char)*str)) str++;
|
||||
if (*str == '\0') return 0;
|
||||
|
||||
char *endptr;
|
||||
errno = 0;
|
||||
int64_t val = strtol(str, &endptr, 10);
|
||||
if (endptr == str || ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (isspace((unsigned char)*endptr)) endptr++;
|
||||
if (*endptr != '\0') return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_value: recursively determine the value of the Wire given its name.
|
||||
int32_t get_value(Wire *wire, char *wire_name) {
|
||||
if (is_int(wire_name)) {
|
||||
return atoi(wire_name);
|
||||
}
|
||||
|
||||
uint32_t index = hash(wire_name);
|
||||
if (wire[index].assigned == true) {
|
||||
return wire[index].value;
|
||||
}
|
||||
|
||||
uint16_t l_operand, r_operand;
|
||||
if (wire[index].l_operand[0] != '\0')
|
||||
l_operand = get_value(wire, wire[index].l_operand);
|
||||
if (wire[index].r_operand[0] != '\0')
|
||||
r_operand = get_value(wire, wire[index].r_operand);
|
||||
|
||||
switch(wire[index].gate) {
|
||||
case ASSIGN:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = r_operand;
|
||||
break;
|
||||
case AND:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand & r_operand;
|
||||
break;
|
||||
case OR:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand | r_operand;
|
||||
break;
|
||||
case LSHIFT:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand << r_operand;
|
||||
break;
|
||||
case RSHIFT:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand >> r_operand;
|
||||
break;
|
||||
case NOT:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = ~r_operand;
|
||||
break;
|
||||
}
|
||||
|
||||
//bad gate
|
||||
perror("get_value: bad gate.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// process: insert each wire definition (i.e., instruction) into the Wire array.
|
||||
void process(Wire *wire, char *left, char *right) {
|
||||
uint32_t index = hash(right);
|
||||
|
||||
if (strstr(left, "AND") != NULL) {
|
||||
sscanf(left, "%s AND %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = AND;
|
||||
} else if (strstr(left, "OR") != NULL) {
|
||||
sscanf(left, "%s OR %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = OR;
|
||||
} else if(strstr(left, "LSHIFT") != NULL) {
|
||||
sscanf(left, "%s LSHIFT %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = LSHIFT;
|
||||
} else if (strstr(left, "RSHIFT") != NULL) {
|
||||
sscanf(left, "%s RSHIFT %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = RSHIFT;
|
||||
} else if (strstr(left, "NOT") != NULL) {
|
||||
sscanf(left, "NOT %s", wire[index].r_operand);
|
||||
wire[index].gate = NOT;
|
||||
} else if (!is_int(left)) { //test for definitions like "x -> y"
|
||||
strcpy(wire[index].r_operand, left);
|
||||
uint64_t len = strlen(wire[index].r_operand);
|
||||
|
||||
//remove trailing whitespace
|
||||
for (uint64_t i = len - 1; i >= 0; i--) {
|
||||
if (isspace((unsigned char)wire[index].r_operand[i])) {
|
||||
wire[index].r_operand[i] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wire[index].gate = ASSIGN;
|
||||
} else { //if we end up here, the definition must be like "123 -> x"
|
||||
wire[index].value = atoi(left);
|
||||
wire[index].assigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t index = 26*26;
|
||||
Wire wire[index];
|
||||
char left[20]; //20 is suffcient to hold the longest possible definition.
|
||||
char right[3]; //3 is sufficient for any one or two character wire name.
|
||||
|
||||
for (uint16_t i = 0; i < index; i++) {
|
||||
wire[i].l_operand[0] = '\0';
|
||||
wire[i].r_operand[0] = '\0';
|
||||
wire[i].gate = ASSIGN;
|
||||
wire[i].assigned = false;
|
||||
wire[i].value = 0;
|
||||
}
|
||||
|
||||
while (fscanf(file, "%20[a-zA-Z0-9 ] -> %s\n", left, right) != EOF) {
|
||||
process(wire, left, right);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("a: %hu\n", get_value(wire, "a"));
|
||||
|
||||
return 0;
|
||||
}
|
175
2015/day07/answer02.c
Normal file
175
2015/day07/answer02.c
Normal file
@ -0,0 +1,175 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef enum {
|
||||
ASSIGN,
|
||||
AND,
|
||||
OR,
|
||||
LSHIFT,
|
||||
RSHIFT,
|
||||
NOT
|
||||
} Gate;
|
||||
|
||||
typedef struct {
|
||||
char l_operand[3];
|
||||
char r_operand[3];
|
||||
Gate gate;
|
||||
bool assigned;
|
||||
uint16_t value;
|
||||
} Wire;
|
||||
|
||||
/* hash: for single character strings, convert the character to its natural index.
|
||||
* for two character strings, treat the string as a base 26 number.
|
||||
* e.g., a -> 0, b -> 1, ..., z -> 25, aa -> 26, ..., etc.
|
||||
*/
|
||||
int32_t hash(char *str) {
|
||||
int32_t length = strlen(str);
|
||||
if (length == 1) {
|
||||
return str[0] - 'a';
|
||||
} else if (length == 2) {
|
||||
return 26 * ((str[0] - 'a') + 1) + (str[1] - 'a');
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// is_int: return 1 if the string argument is an integer; 0 otherwise.
|
||||
int32_t is_int(char *str) {
|
||||
while (isspace((unsigned char)*str)) str++;
|
||||
if (*str == '\0') return 0;
|
||||
|
||||
char *endptr;
|
||||
errno = 0;
|
||||
int64_t val = strtol(str, &endptr, 10);
|
||||
if (endptr == str || ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (isspace((unsigned char)*endptr)) endptr++;
|
||||
if (*endptr != '\0') return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_value: recursively determine the value of the Wire given its name.
|
||||
int32_t get_value(Wire *wire, char *wire_name) {
|
||||
if (is_int(wire_name)) {
|
||||
return atoi(wire_name);
|
||||
}
|
||||
|
||||
uint32_t index = hash(wire_name);
|
||||
if (wire[index].assigned == true) {
|
||||
return wire[index].value;
|
||||
}
|
||||
|
||||
uint16_t l_operand, r_operand;
|
||||
if (wire[index].l_operand[0] != '\0')
|
||||
l_operand = get_value(wire, wire[index].l_operand);
|
||||
if (wire[index].r_operand[0] != '\0')
|
||||
r_operand = get_value(wire, wire[index].r_operand);
|
||||
|
||||
switch(wire[index].gate) {
|
||||
case ASSIGN:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = r_operand;
|
||||
break;
|
||||
case AND:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand & r_operand;
|
||||
break;
|
||||
case OR:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand | r_operand;
|
||||
break;
|
||||
case LSHIFT:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand << r_operand;
|
||||
break;
|
||||
case RSHIFT:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = l_operand >> r_operand;
|
||||
break;
|
||||
case NOT:
|
||||
wire[index].assigned = true;
|
||||
return wire[index].value = ~r_operand;
|
||||
break;
|
||||
}
|
||||
|
||||
//bad gate
|
||||
perror("get_value: bad gate.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// process: insert each wire definition (i.e., instruction) into the Wire array.
|
||||
void process(Wire *wire, char *left, char *right) {
|
||||
uint32_t index = hash(right);
|
||||
|
||||
if (strstr(left, "AND") != NULL) {
|
||||
sscanf(left, "%s AND %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = AND;
|
||||
} else if (strstr(left, "OR") != NULL) {
|
||||
sscanf(left, "%s OR %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = OR;
|
||||
} else if(strstr(left, "LSHIFT") != NULL) {
|
||||
sscanf(left, "%s LSHIFT %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = LSHIFT;
|
||||
} else if (strstr(left, "RSHIFT") != NULL) {
|
||||
sscanf(left, "%s RSHIFT %s", wire[index].l_operand, wire[index].r_operand);
|
||||
wire[index].gate = RSHIFT;
|
||||
} else if (strstr(left, "NOT") != NULL) {
|
||||
sscanf(left, "NOT %s", wire[index].r_operand);
|
||||
wire[index].gate = NOT;
|
||||
} else if (!is_int(left)) { //test for definitions like "x -> y"
|
||||
strcpy(wire[index].r_operand, left);
|
||||
uint64_t len = strlen(wire[index].r_operand);
|
||||
|
||||
//remove trailing whitespace
|
||||
for (uint64_t i = len - 1; i >= 0; i--) {
|
||||
if (isspace((unsigned char)wire[index].r_operand[i])) {
|
||||
wire[index].r_operand[i] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wire[index].gate = ASSIGN;
|
||||
} else { //if we end up here, the definition must be like "123 -> x"
|
||||
wire[index].value = atoi(left);
|
||||
wire[index].assigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("input2", "r");
|
||||
if (file == NULL) {
|
||||
perror("main: error opening file.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t index = 26*26;
|
||||
Wire wire[index];
|
||||
char left[20]; //20 is suffcient to hold the longest possible definition.
|
||||
char right[3]; //3 is sufficient for any one or two character wire name.
|
||||
|
||||
for (uint16_t i = 0; i < index; i++) {
|
||||
wire[i].l_operand[0] = '\0';
|
||||
wire[i].r_operand[0] = '\0';
|
||||
wire[i].gate = ASSIGN;
|
||||
wire[i].assigned = false;
|
||||
wire[i].value = 0;
|
||||
}
|
||||
|
||||
while (fscanf(file, "%20[a-zA-Z0-9 ] -> %s\n", left, right) != EOF) {
|
||||
process(wire, left, right);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
printf("a: %hu\n", get_value(wire, "a"));
|
||||
|
||||
return 0;
|
||||
}
|
339
2015/day07/input
Normal file
339
2015/day07/input
Normal file
@ -0,0 +1,339 @@
|
||||
af AND ah -> ai
|
||||
NOT lk -> ll
|
||||
hz RSHIFT 1 -> is
|
||||
NOT go -> gp
|
||||
du OR dt -> dv
|
||||
x RSHIFT 5 -> aa
|
||||
at OR az -> ba
|
||||
eo LSHIFT 15 -> es
|
||||
ci OR ct -> cu
|
||||
b RSHIFT 5 -> f
|
||||
fm OR fn -> fo
|
||||
NOT ag -> ah
|
||||
v OR w -> x
|
||||
g AND i -> j
|
||||
an LSHIFT 15 -> ar
|
||||
1 AND cx -> cy
|
||||
jq AND jw -> jy
|
||||
iu RSHIFT 5 -> ix
|
||||
gl AND gm -> go
|
||||
NOT bw -> bx
|
||||
jp RSHIFT 3 -> jr
|
||||
hg AND hh -> hj
|
||||
bv AND bx -> by
|
||||
er OR es -> et
|
||||
kl OR kr -> ks
|
||||
et RSHIFT 1 -> fm
|
||||
e AND f -> h
|
||||
u LSHIFT 1 -> ao
|
||||
he RSHIFT 1 -> hx
|
||||
eg AND ei -> ej
|
||||
bo AND bu -> bw
|
||||
dz OR ef -> eg
|
||||
dy RSHIFT 3 -> ea
|
||||
gl OR gm -> gn
|
||||
da LSHIFT 1 -> du
|
||||
au OR av -> aw
|
||||
gj OR gu -> gv
|
||||
eu OR fa -> fb
|
||||
lg OR lm -> ln
|
||||
e OR f -> g
|
||||
NOT dm -> dn
|
||||
NOT l -> m
|
||||
aq OR ar -> as
|
||||
gj RSHIFT 5 -> gm
|
||||
hm AND ho -> hp
|
||||
ge LSHIFT 15 -> gi
|
||||
jp RSHIFT 1 -> ki
|
||||
hg OR hh -> hi
|
||||
lc LSHIFT 1 -> lw
|
||||
km OR kn -> ko
|
||||
eq LSHIFT 1 -> fk
|
||||
1 AND am -> an
|
||||
gj RSHIFT 1 -> hc
|
||||
aj AND al -> am
|
||||
gj AND gu -> gw
|
||||
ko AND kq -> kr
|
||||
ha OR gz -> hb
|
||||
bn OR by -> bz
|
||||
iv OR jb -> jc
|
||||
NOT ac -> ad
|
||||
bo OR bu -> bv
|
||||
d AND j -> l
|
||||
bk LSHIFT 1 -> ce
|
||||
de OR dk -> dl
|
||||
dd RSHIFT 1 -> dw
|
||||
hz AND ik -> im
|
||||
NOT jd -> je
|
||||
fo RSHIFT 2 -> fp
|
||||
hb LSHIFT 1 -> hv
|
||||
lf RSHIFT 2 -> lg
|
||||
gj RSHIFT 3 -> gl
|
||||
ki OR kj -> kk
|
||||
NOT ak -> al
|
||||
ld OR le -> lf
|
||||
ci RSHIFT 3 -> ck
|
||||
1 AND cc -> cd
|
||||
NOT kx -> ky
|
||||
fp OR fv -> fw
|
||||
ev AND ew -> ey
|
||||
dt LSHIFT 15 -> dx
|
||||
NOT ax -> ay
|
||||
bp AND bq -> bs
|
||||
NOT ii -> ij
|
||||
ci AND ct -> cv
|
||||
iq OR ip -> ir
|
||||
x RSHIFT 2 -> y
|
||||
fq OR fr -> fs
|
||||
bn RSHIFT 5 -> bq
|
||||
0 -> c
|
||||
14146 -> b
|
||||
d OR j -> k
|
||||
z OR aa -> ab
|
||||
gf OR ge -> gg
|
||||
df OR dg -> dh
|
||||
NOT hj -> hk
|
||||
NOT di -> dj
|
||||
fj LSHIFT 15 -> fn
|
||||
lf RSHIFT 1 -> ly
|
||||
b AND n -> p
|
||||
jq OR jw -> jx
|
||||
gn AND gp -> gq
|
||||
x RSHIFT 1 -> aq
|
||||
ex AND ez -> fa
|
||||
NOT fc -> fd
|
||||
bj OR bi -> bk
|
||||
as RSHIFT 5 -> av
|
||||
hu LSHIFT 15 -> hy
|
||||
NOT gs -> gt
|
||||
fs AND fu -> fv
|
||||
dh AND dj -> dk
|
||||
bz AND cb -> cc
|
||||
dy RSHIFT 1 -> er
|
||||
hc OR hd -> he
|
||||
fo OR fz -> ga
|
||||
t OR s -> u
|
||||
b RSHIFT 2 -> d
|
||||
NOT jy -> jz
|
||||
hz RSHIFT 2 -> ia
|
||||
kk AND kv -> kx
|
||||
ga AND gc -> gd
|
||||
fl LSHIFT 1 -> gf
|
||||
bn AND by -> ca
|
||||
NOT hr -> hs
|
||||
NOT bs -> bt
|
||||
lf RSHIFT 3 -> lh
|
||||
au AND av -> ax
|
||||
1 AND gd -> ge
|
||||
jr OR js -> jt
|
||||
fw AND fy -> fz
|
||||
NOT iz -> ja
|
||||
c LSHIFT 1 -> t
|
||||
dy RSHIFT 5 -> eb
|
||||
bp OR bq -> br
|
||||
NOT h -> i
|
||||
1 AND ds -> dt
|
||||
ab AND ad -> ae
|
||||
ap LSHIFT 1 -> bj
|
||||
br AND bt -> bu
|
||||
NOT ca -> cb
|
||||
NOT el -> em
|
||||
s LSHIFT 15 -> w
|
||||
gk OR gq -> gr
|
||||
ff AND fh -> fi
|
||||
kf LSHIFT 15 -> kj
|
||||
fp AND fv -> fx
|
||||
lh OR li -> lj
|
||||
bn RSHIFT 3 -> bp
|
||||
jp OR ka -> kb
|
||||
lw OR lv -> lx
|
||||
iy AND ja -> jb
|
||||
dy OR ej -> ek
|
||||
1 AND bh -> bi
|
||||
NOT kt -> ku
|
||||
ao OR an -> ap
|
||||
ia AND ig -> ii
|
||||
NOT ey -> ez
|
||||
bn RSHIFT 1 -> cg
|
||||
fk OR fj -> fl
|
||||
ce OR cd -> cf
|
||||
eu AND fa -> fc
|
||||
kg OR kf -> kh
|
||||
jr AND js -> ju
|
||||
iu RSHIFT 3 -> iw
|
||||
df AND dg -> di
|
||||
dl AND dn -> do
|
||||
la LSHIFT 15 -> le
|
||||
fo RSHIFT 1 -> gh
|
||||
NOT gw -> gx
|
||||
NOT gb -> gc
|
||||
ir LSHIFT 1 -> jl
|
||||
x AND ai -> ak
|
||||
he RSHIFT 5 -> hh
|
||||
1 AND lu -> lv
|
||||
NOT ft -> fu
|
||||
gh OR gi -> gj
|
||||
lf RSHIFT 5 -> li
|
||||
x RSHIFT 3 -> z
|
||||
b RSHIFT 3 -> e
|
||||
he RSHIFT 2 -> hf
|
||||
NOT fx -> fy
|
||||
jt AND jv -> jw
|
||||
hx OR hy -> hz
|
||||
jp AND ka -> kc
|
||||
fb AND fd -> fe
|
||||
hz OR ik -> il
|
||||
ci RSHIFT 1 -> db
|
||||
fo AND fz -> gb
|
||||
fq AND fr -> ft
|
||||
gj RSHIFT 2 -> gk
|
||||
cg OR ch -> ci
|
||||
cd LSHIFT 15 -> ch
|
||||
jm LSHIFT 1 -> kg
|
||||
ih AND ij -> ik
|
||||
fo RSHIFT 3 -> fq
|
||||
fo RSHIFT 5 -> fr
|
||||
1 AND fi -> fj
|
||||
1 AND kz -> la
|
||||
iu AND jf -> jh
|
||||
cq AND cs -> ct
|
||||
dv LSHIFT 1 -> ep
|
||||
hf OR hl -> hm
|
||||
km AND kn -> kp
|
||||
de AND dk -> dm
|
||||
dd RSHIFT 5 -> dg
|
||||
NOT lo -> lp
|
||||
NOT ju -> jv
|
||||
NOT fg -> fh
|
||||
cm AND co -> cp
|
||||
ea AND eb -> ed
|
||||
dd RSHIFT 3 -> df
|
||||
gr AND gt -> gu
|
||||
ep OR eo -> eq
|
||||
cj AND cp -> cr
|
||||
lf OR lq -> lr
|
||||
gg LSHIFT 1 -> ha
|
||||
et RSHIFT 2 -> eu
|
||||
NOT jh -> ji
|
||||
ek AND em -> en
|
||||
jk LSHIFT 15 -> jo
|
||||
ia OR ig -> ih
|
||||
gv AND gx -> gy
|
||||
et AND fe -> fg
|
||||
lh AND li -> lk
|
||||
1 AND io -> ip
|
||||
kb AND kd -> ke
|
||||
kk RSHIFT 5 -> kn
|
||||
id AND if -> ig
|
||||
NOT ls -> lt
|
||||
dw OR dx -> dy
|
||||
dd AND do -> dq
|
||||
lf AND lq -> ls
|
||||
NOT kc -> kd
|
||||
dy AND ej -> el
|
||||
1 AND ke -> kf
|
||||
et OR fe -> ff
|
||||
hz RSHIFT 5 -> ic
|
||||
dd OR do -> dp
|
||||
cj OR cp -> cq
|
||||
NOT dq -> dr
|
||||
kk RSHIFT 1 -> ld
|
||||
jg AND ji -> jj
|
||||
he OR hp -> hq
|
||||
hi AND hk -> hl
|
||||
dp AND dr -> ds
|
||||
dz AND ef -> eh
|
||||
hz RSHIFT 3 -> ib
|
||||
db OR dc -> dd
|
||||
hw LSHIFT 1 -> iq
|
||||
he AND hp -> hr
|
||||
NOT cr -> cs
|
||||
lg AND lm -> lo
|
||||
hv OR hu -> hw
|
||||
il AND in -> io
|
||||
NOT eh -> ei
|
||||
gz LSHIFT 15 -> hd
|
||||
gk AND gq -> gs
|
||||
1 AND en -> eo
|
||||
NOT kp -> kq
|
||||
et RSHIFT 5 -> ew
|
||||
lj AND ll -> lm
|
||||
he RSHIFT 3 -> hg
|
||||
et RSHIFT 3 -> ev
|
||||
as AND bd -> bf
|
||||
cu AND cw -> cx
|
||||
jx AND jz -> ka
|
||||
b OR n -> o
|
||||
be AND bg -> bh
|
||||
1 AND ht -> hu
|
||||
1 AND gy -> gz
|
||||
NOT hn -> ho
|
||||
ck OR cl -> cm
|
||||
ec AND ee -> ef
|
||||
lv LSHIFT 15 -> lz
|
||||
ks AND ku -> kv
|
||||
NOT ie -> if
|
||||
hf AND hl -> hn
|
||||
1 AND r -> s
|
||||
ib AND ic -> ie
|
||||
hq AND hs -> ht
|
||||
y AND ae -> ag
|
||||
NOT ed -> ee
|
||||
bi LSHIFT 15 -> bm
|
||||
dy RSHIFT 2 -> dz
|
||||
ci RSHIFT 2 -> cj
|
||||
NOT bf -> bg
|
||||
NOT im -> in
|
||||
ev OR ew -> ex
|
||||
ib OR ic -> id
|
||||
bn RSHIFT 2 -> bo
|
||||
dd RSHIFT 2 -> de
|
||||
bl OR bm -> bn
|
||||
as RSHIFT 1 -> bl
|
||||
ea OR eb -> ec
|
||||
ln AND lp -> lq
|
||||
kk RSHIFT 3 -> km
|
||||
is OR it -> iu
|
||||
iu RSHIFT 2 -> iv
|
||||
as OR bd -> be
|
||||
ip LSHIFT 15 -> it
|
||||
iw OR ix -> iy
|
||||
kk RSHIFT 2 -> kl
|
||||
NOT bb -> bc
|
||||
ci RSHIFT 5 -> cl
|
||||
ly OR lz -> ma
|
||||
z AND aa -> ac
|
||||
iu RSHIFT 1 -> jn
|
||||
cy LSHIFT 15 -> dc
|
||||
cf LSHIFT 1 -> cz
|
||||
as RSHIFT 3 -> au
|
||||
cz OR cy -> da
|
||||
kw AND ky -> kz
|
||||
lx -> a
|
||||
iw AND ix -> iz
|
||||
lr AND lt -> lu
|
||||
jp RSHIFT 5 -> js
|
||||
aw AND ay -> az
|
||||
jc AND je -> jf
|
||||
lb OR la -> lc
|
||||
NOT cn -> co
|
||||
kh LSHIFT 1 -> lb
|
||||
1 AND jj -> jk
|
||||
y OR ae -> af
|
||||
ck AND cl -> cn
|
||||
kk OR kv -> kw
|
||||
NOT cv -> cw
|
||||
kl AND kr -> kt
|
||||
iu OR jf -> jg
|
||||
at AND az -> bb
|
||||
jp RSHIFT 2 -> jq
|
||||
iv AND jb -> jd
|
||||
jn OR jo -> jp
|
||||
x OR ai -> aj
|
||||
ba AND bc -> bd
|
||||
jl OR jk -> jm
|
||||
b RSHIFT 1 -> v
|
||||
o AND q -> r
|
||||
NOT p -> q
|
||||
k AND m -> n
|
||||
as RSHIFT 2 -> at
|
339
2015/day07/input2
Normal file
339
2015/day07/input2
Normal file
@ -0,0 +1,339 @@
|
||||
af AND ah -> ai
|
||||
NOT lk -> ll
|
||||
hz RSHIFT 1 -> is
|
||||
NOT go -> gp
|
||||
du OR dt -> dv
|
||||
x RSHIFT 5 -> aa
|
||||
at OR az -> ba
|
||||
eo LSHIFT 15 -> es
|
||||
ci OR ct -> cu
|
||||
b RSHIFT 5 -> f
|
||||
fm OR fn -> fo
|
||||
NOT ag -> ah
|
||||
v OR w -> x
|
||||
g AND i -> j
|
||||
an LSHIFT 15 -> ar
|
||||
1 AND cx -> cy
|
||||
jq AND jw -> jy
|
||||
iu RSHIFT 5 -> ix
|
||||
gl AND gm -> go
|
||||
NOT bw -> bx
|
||||
jp RSHIFT 3 -> jr
|
||||
hg AND hh -> hj
|
||||
bv AND bx -> by
|
||||
er OR es -> et
|
||||
kl OR kr -> ks
|
||||
et RSHIFT 1 -> fm
|
||||
e AND f -> h
|
||||
u LSHIFT 1 -> ao
|
||||
he RSHIFT 1 -> hx
|
||||
eg AND ei -> ej
|
||||
bo AND bu -> bw
|
||||
dz OR ef -> eg
|
||||
dy RSHIFT 3 -> ea
|
||||
gl OR gm -> gn
|
||||
da LSHIFT 1 -> du
|
||||
au OR av -> aw
|
||||
gj OR gu -> gv
|
||||
eu OR fa -> fb
|
||||
lg OR lm -> ln
|
||||
e OR f -> g
|
||||
NOT dm -> dn
|
||||
NOT l -> m
|
||||
aq OR ar -> as
|
||||
gj RSHIFT 5 -> gm
|
||||
hm AND ho -> hp
|
||||
ge LSHIFT 15 -> gi
|
||||
jp RSHIFT 1 -> ki
|
||||
hg OR hh -> hi
|
||||
lc LSHIFT 1 -> lw
|
||||
km OR kn -> ko
|
||||
eq LSHIFT 1 -> fk
|
||||
1 AND am -> an
|
||||
gj RSHIFT 1 -> hc
|
||||
aj AND al -> am
|
||||
gj AND gu -> gw
|
||||
ko AND kq -> kr
|
||||
ha OR gz -> hb
|
||||
bn OR by -> bz
|
||||
iv OR jb -> jc
|
||||
NOT ac -> ad
|
||||
bo OR bu -> bv
|
||||
d AND j -> l
|
||||
bk LSHIFT 1 -> ce
|
||||
de OR dk -> dl
|
||||
dd RSHIFT 1 -> dw
|
||||
hz AND ik -> im
|
||||
NOT jd -> je
|
||||
fo RSHIFT 2 -> fp
|
||||
hb LSHIFT 1 -> hv
|
||||
lf RSHIFT 2 -> lg
|
||||
gj RSHIFT 3 -> gl
|
||||
ki OR kj -> kk
|
||||
NOT ak -> al
|
||||
ld OR le -> lf
|
||||
ci RSHIFT 3 -> ck
|
||||
1 AND cc -> cd
|
||||
NOT kx -> ky
|
||||
fp OR fv -> fw
|
||||
ev AND ew -> ey
|
||||
dt LSHIFT 15 -> dx
|
||||
NOT ax -> ay
|
||||
bp AND bq -> bs
|
||||
NOT ii -> ij
|
||||
ci AND ct -> cv
|
||||
iq OR ip -> ir
|
||||
x RSHIFT 2 -> y
|
||||
fq OR fr -> fs
|
||||
bn RSHIFT 5 -> bq
|
||||
0 -> c
|
||||
956 -> b
|
||||
d OR j -> k
|
||||
z OR aa -> ab
|
||||
gf OR ge -> gg
|
||||
df OR dg -> dh
|
||||
NOT hj -> hk
|
||||
NOT di -> dj
|
||||
fj LSHIFT 15 -> fn
|
||||
lf RSHIFT 1 -> ly
|
||||
b AND n -> p
|
||||
jq OR jw -> jx
|
||||
gn AND gp -> gq
|
||||
x RSHIFT 1 -> aq
|
||||
ex AND ez -> fa
|
||||
NOT fc -> fd
|
||||
bj OR bi -> bk
|
||||
as RSHIFT 5 -> av
|
||||
hu LSHIFT 15 -> hy
|
||||
NOT gs -> gt
|
||||
fs AND fu -> fv
|
||||
dh AND dj -> dk
|
||||
bz AND cb -> cc
|
||||
dy RSHIFT 1 -> er
|
||||
hc OR hd -> he
|
||||
fo OR fz -> ga
|
||||
t OR s -> u
|
||||
b RSHIFT 2 -> d
|
||||
NOT jy -> jz
|
||||
hz RSHIFT 2 -> ia
|
||||
kk AND kv -> kx
|
||||
ga AND gc -> gd
|
||||
fl LSHIFT 1 -> gf
|
||||
bn AND by -> ca
|
||||
NOT hr -> hs
|
||||
NOT bs -> bt
|
||||
lf RSHIFT 3 -> lh
|
||||
au AND av -> ax
|
||||
1 AND gd -> ge
|
||||
jr OR js -> jt
|
||||
fw AND fy -> fz
|
||||
NOT iz -> ja
|
||||
c LSHIFT 1 -> t
|
||||
dy RSHIFT 5 -> eb
|
||||
bp OR bq -> br
|
||||
NOT h -> i
|
||||
1 AND ds -> dt
|
||||
ab AND ad -> ae
|
||||
ap LSHIFT 1 -> bj
|
||||
br AND bt -> bu
|
||||
NOT ca -> cb
|
||||
NOT el -> em
|
||||
s LSHIFT 15 -> w
|
||||
gk OR gq -> gr
|
||||
ff AND fh -> fi
|
||||
kf LSHIFT 15 -> kj
|
||||
fp AND fv -> fx
|
||||
lh OR li -> lj
|
||||
bn RSHIFT 3 -> bp
|
||||
jp OR ka -> kb
|
||||
lw OR lv -> lx
|
||||
iy AND ja -> jb
|
||||
dy OR ej -> ek
|
||||
1 AND bh -> bi
|
||||
NOT kt -> ku
|
||||
ao OR an -> ap
|
||||
ia AND ig -> ii
|
||||
NOT ey -> ez
|
||||
bn RSHIFT 1 -> cg
|
||||
fk OR fj -> fl
|
||||
ce OR cd -> cf
|
||||
eu AND fa -> fc
|
||||
kg OR kf -> kh
|
||||
jr AND js -> ju
|
||||
iu RSHIFT 3 -> iw
|
||||
df AND dg -> di
|
||||
dl AND dn -> do
|
||||
la LSHIFT 15 -> le
|
||||
fo RSHIFT 1 -> gh
|
||||
NOT gw -> gx
|
||||
NOT gb -> gc
|
||||
ir LSHIFT 1 -> jl
|
||||
x AND ai -> ak
|
||||
he RSHIFT 5 -> hh
|
||||
1 AND lu -> lv
|
||||
NOT ft -> fu
|
||||
gh OR gi -> gj
|
||||
lf RSHIFT 5 -> li
|
||||
x RSHIFT 3 -> z
|
||||
b RSHIFT 3 -> e
|
||||
he RSHIFT 2 -> hf
|
||||
NOT fx -> fy
|
||||
jt AND jv -> jw
|
||||
hx OR hy -> hz
|
||||
jp AND ka -> kc
|
||||
fb AND fd -> fe
|
||||
hz OR ik -> il
|
||||
ci RSHIFT 1 -> db
|
||||
fo AND fz -> gb
|
||||
fq AND fr -> ft
|
||||
gj RSHIFT 2 -> gk
|
||||
cg OR ch -> ci
|
||||
cd LSHIFT 15 -> ch
|
||||
jm LSHIFT 1 -> kg
|
||||
ih AND ij -> ik
|
||||
fo RSHIFT 3 -> fq
|
||||
fo RSHIFT 5 -> fr
|
||||
1 AND fi -> fj
|
||||
1 AND kz -> la
|
||||
iu AND jf -> jh
|
||||
cq AND cs -> ct
|
||||
dv LSHIFT 1 -> ep
|
||||
hf OR hl -> hm
|
||||
km AND kn -> kp
|
||||
de AND dk -> dm
|
||||
dd RSHIFT 5 -> dg
|
||||
NOT lo -> lp
|
||||
NOT ju -> jv
|
||||
NOT fg -> fh
|
||||
cm AND co -> cp
|
||||
ea AND eb -> ed
|
||||
dd RSHIFT 3 -> df
|
||||
gr AND gt -> gu
|
||||
ep OR eo -> eq
|
||||
cj AND cp -> cr
|
||||
lf OR lq -> lr
|
||||
gg LSHIFT 1 -> ha
|
||||
et RSHIFT 2 -> eu
|
||||
NOT jh -> ji
|
||||
ek AND em -> en
|
||||
jk LSHIFT 15 -> jo
|
||||
ia OR ig -> ih
|
||||
gv AND gx -> gy
|
||||
et AND fe -> fg
|
||||
lh AND li -> lk
|
||||
1 AND io -> ip
|
||||
kb AND kd -> ke
|
||||
kk RSHIFT 5 -> kn
|
||||
id AND if -> ig
|
||||
NOT ls -> lt
|
||||
dw OR dx -> dy
|
||||
dd AND do -> dq
|
||||
lf AND lq -> ls
|
||||
NOT kc -> kd
|
||||
dy AND ej -> el
|
||||
1 AND ke -> kf
|
||||
et OR fe -> ff
|
||||
hz RSHIFT 5 -> ic
|
||||
dd OR do -> dp
|
||||
cj OR cp -> cq
|
||||
NOT dq -> dr
|
||||
kk RSHIFT 1 -> ld
|
||||
jg AND ji -> jj
|
||||
he OR hp -> hq
|
||||
hi AND hk -> hl
|
||||
dp AND dr -> ds
|
||||
dz AND ef -> eh
|
||||
hz RSHIFT 3 -> ib
|
||||
db OR dc -> dd
|
||||
hw LSHIFT 1 -> iq
|
||||
he AND hp -> hr
|
||||
NOT cr -> cs
|
||||
lg AND lm -> lo
|
||||
hv OR hu -> hw
|
||||
il AND in -> io
|
||||
NOT eh -> ei
|
||||
gz LSHIFT 15 -> hd
|
||||
gk AND gq -> gs
|
||||
1 AND en -> eo
|
||||
NOT kp -> kq
|
||||
et RSHIFT 5 -> ew
|
||||
lj AND ll -> lm
|
||||
he RSHIFT 3 -> hg
|
||||
et RSHIFT 3 -> ev
|
||||
as AND bd -> bf
|
||||
cu AND cw -> cx
|
||||
jx AND jz -> ka
|
||||
b OR n -> o
|
||||
be AND bg -> bh
|
||||
1 AND ht -> hu
|
||||
1 AND gy -> gz
|
||||
NOT hn -> ho
|
||||
ck OR cl -> cm
|
||||
ec AND ee -> ef
|
||||
lv LSHIFT 15 -> lz
|
||||
ks AND ku -> kv
|
||||
NOT ie -> if
|
||||
hf AND hl -> hn
|
||||
1 AND r -> s
|
||||
ib AND ic -> ie
|
||||
hq AND hs -> ht
|
||||
y AND ae -> ag
|
||||
NOT ed -> ee
|
||||
bi LSHIFT 15 -> bm
|
||||
dy RSHIFT 2 -> dz
|
||||
ci RSHIFT 2 -> cj
|
||||
NOT bf -> bg
|
||||
NOT im -> in
|
||||
ev OR ew -> ex
|
||||
ib OR ic -> id
|
||||
bn RSHIFT 2 -> bo
|
||||
dd RSHIFT 2 -> de
|
||||
bl OR bm -> bn
|
||||
as RSHIFT 1 -> bl
|
||||
ea OR eb -> ec
|
||||
ln AND lp -> lq
|
||||
kk RSHIFT 3 -> km
|
||||
is OR it -> iu
|
||||
iu RSHIFT 2 -> iv
|
||||
as OR bd -> be
|
||||
ip LSHIFT 15 -> it
|
||||
iw OR ix -> iy
|
||||
kk RSHIFT 2 -> kl
|
||||
NOT bb -> bc
|
||||
ci RSHIFT 5 -> cl
|
||||
ly OR lz -> ma
|
||||
z AND aa -> ac
|
||||
iu RSHIFT 1 -> jn
|
||||
cy LSHIFT 15 -> dc
|
||||
cf LSHIFT 1 -> cz
|
||||
as RSHIFT 3 -> au
|
||||
cz OR cy -> da
|
||||
kw AND ky -> kz
|
||||
lx -> a
|
||||
iw AND ix -> iz
|
||||
lr AND lt -> lu
|
||||
jp RSHIFT 5 -> js
|
||||
aw AND ay -> az
|
||||
jc AND je -> jf
|
||||
lb OR la -> lc
|
||||
NOT cn -> co
|
||||
kh LSHIFT 1 -> lb
|
||||
1 AND jj -> jk
|
||||
y OR ae -> af
|
||||
ck AND cl -> cn
|
||||
kk OR kv -> kw
|
||||
NOT cv -> cw
|
||||
kl AND kr -> kt
|
||||
iu OR jf -> jg
|
||||
at AND az -> bb
|
||||
jp RSHIFT 2 -> jq
|
||||
iv AND jb -> jd
|
||||
jn OR jo -> jp
|
||||
x OR ai -> aj
|
||||
ba AND bc -> bd
|
||||
jl OR jk -> jm
|
||||
b RSHIFT 1 -> v
|
||||
o AND q -> r
|
||||
NOT p -> q
|
||||
k AND m -> n
|
||||
as RSHIFT 2 -> at
|
16
2015/day07/makefile
Normal file
16
2015/day07/makefile
Normal file
@ -0,0 +1,16 @@
|
||||
CC = gcc
|
||||
CFLAGS = -std=c99 -Wall -Wextra
|
||||
LDFLAGS =
|
||||
DFLAGS = -std=c99 -Wall -Wextra -g
|
||||
|
||||
1: answer01.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer01.c -o answer01
|
||||
|
||||
2: answer02.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) answer02.c -o answer02
|
||||
|
||||
1d: answer01.c
|
||||
$(CC) $(DFLAGS) $(LDFLAGS) answer01.c -o answer01
|
||||
|
||||
2d: answer02.c
|
||||
$(CC) $(DFLAGS) $(LDFLAGS) answer02.c -o answer02
|
Loading…
Reference in New Issue
user.block.title