Last active
February 14, 2016 05:03
-
-
Save jmagnuson/d1dce0548645d88e096e to your computer and use it in GitHub Desktop.
Advent of Code 2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
/** | |
* '(' = 40 | |
* ')' = 41 | |
* | |
* '(' -> +1 floor | |
* ')' -> -1 floor | |
* | |
**/ | |
int main(int argc, char* argv[]) { | |
FILE *rfd; | |
rfd = fopen(argv[1], "rb"); | |
int count = 0; | |
int sum = 0; | |
int val = 0; | |
loop: | |
val = fgetc(rfd); | |
if(val>=40) | |
{ | |
sum += val; | |
count++; | |
goto loop; | |
} | |
int net = 81*count- 2*sum; | |
printf("Count: %d\n", count); | |
printf("Sum: %d\n", sum); | |
printf("Net: %d\n", net); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
char checkStraight(char carray[], int len) { | |
char c_hold = carray[0]; | |
int count = 1, i; | |
for (i = 1; i < len; i++) { | |
if (carray[i] == c_hold+1) { | |
count++; | |
} | |
else { | |
count=1; | |
} | |
c_hold = carray[i]; | |
if (count==3) { return 1; } | |
} | |
return 0; | |
} | |
char checkTwoDoubles(char carray[], int len) { | |
char c_hold = carray[0]; | |
int count = 0, i = 0; | |
for (i = 1; i < len; i++) { | |
if (carray[i] == c_hold) { | |
count++; | |
c_hold = 0; | |
} | |
else { | |
c_hold = carray[i]; | |
} | |
if (count==2) { | |
return 1; | |
} | |
} | |
return 0; | |
} | |
void incrementCharArray(char carray[], int len) { | |
char carry = 0; | |
int i = len-1; | |
do { | |
if ( carray[i]+1 == 'i' | |
|| carray[i]+1 == 'o' | |
|| carray[i]+1 == 'l') | |
{ | |
carray[i] += 2; | |
carry = 0; | |
} else if (carray[i] == 'z') { | |
carray[i] = 'a'; | |
carry = 1; | |
} else { | |
carray[i] += 1; | |
carry = 0; | |
} | |
i--; | |
} while (carry && i >= 0); | |
} | |
int main(int argc, char *argv[]) { | |
char carray[] = "vzbxkghb"; | |
int len = strlen(carray); | |
while (1) { | |
if (checkStraight(carray, len) | |
&& checkTwoDoubles(carray, len)) | |
{ | |
break; | |
} | |
incrementCharArray(carray, len); | |
} | |
printf("Word: %s\n", carray); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAPDIM 200 | |
int main(int argc, char* argv[]) { | |
FILE *rfd; | |
rfd = fopen(argv[1], "rb"); | |
int val = 0; | |
int count = 0; | |
static void *larray[255]; | |
for (count=0; count<255; count++) | |
{ | |
larray[count] = &&end; | |
} | |
count = 0; | |
larray['<'+1] = &&calc; // 60, x-- | |
larray['>'+1] = &&calc; // 62, x++ | |
larray['^'+1] = &&calc; // 94, y++ | |
larray['v'+1] = &&calc; // 118, y-- | |
int housemap[MAPDIM*MAPDIM]={0}; | |
int x=MAPDIM/2, y=MAPDIM/2; | |
loop: | |
val = fgetc(rfd); | |
goto *larray[val+1]; | |
calc: | |
x += ((~(val>>6))&0b1) * (((val>>1)&0b1)*2 - 1); | |
y += ((val>>6)&0b1) * (1 - ((val>>5)&0b1)*2); | |
housemap[x*MAPDIM+y]++; | |
goto loop; | |
end: | |
val = 0; | |
for (count=0; count<MAPDIM*MAPDIM; count++) { | |
val = val + (housemap[count]>0); | |
} | |
printf("x_end: %d\n", x); | |
printf("y_end: %d\n", y); | |
printf("Houses: %d\n", val); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define DIM 1000 | |
int main(int argc, char* argv[]) { | |
FILE *rfd; | |
rfd = fopen(argv[1], "rb"); | |
int val = 0; | |
int count = 0; | |
int op = -1; | |
int i=0, j=0, num[4]={0}, numi=0; | |
int lines = 0; | |
int lcount = 0; | |
//clock_t start_time=0, end_time=0, tot_time=0; | |
static void *larray[255]; | |
for (count=0; count<255; count++) | |
{ | |
larray[count] = &&loop; | |
} | |
for (count=('0'+1); count < ('9'+2); count++ ) | |
{ | |
larray[count] = &&number; | |
} | |
count = 0; | |
larray[' '+1] = &&space; | |
larray[','+1] = &, | |
larray['\n'+1] = &&newline; | |
larray[0] = &&end; | |
larray[EOF+1] = &&end; | |
int mat[DIM*DIM]={0}; | |
for (i=0; i < DIM*DIM; i++) { | |
mat[i]=0; | |
} | |
goto read6; | |
loop: | |
count++; | |
val = fgetc(rfd); | |
goto *larray[val+1]; | |
space: | |
if (op<0) op = count-1; | |
else { | |
numi++; | |
count = 9; | |
while (--count) | |
fgetc(rfd); | |
} | |
goto loop; | |
comma: | |
numi++; | |
goto loop; | |
number: | |
num[numi] = num[numi]*10 + (val-48); | |
goto loop; | |
newline: | |
lines++; | |
for (i = num[0]; i <= num[2]; i++) { | |
for (j = num[1]; j <= num[3]; j++) { | |
mat[i*DIM+j] = | |
(op&1)|(~(mat[i*DIM+j]|((op>>1)))&1); | |
lcount++; | |
} | |
} | |
do { | |
num[numi]=0; | |
} while (numi--); | |
numi=0; | |
op = -1; | |
read6: | |
count = 7; | |
while (--count) | |
fgetc(rfd); | |
goto loop; | |
end: | |
val = 0; | |
for (count=0; count<DIM*DIM; count++) { | |
val = val + (mat[count]>0); | |
} | |
printf("val: %d\n", val); | |
printf("lcount: %d\n", lcount); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment