Code cleanup
This commit is contained in:
parent
0a7aaec503
commit
fc4cacf492
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ compile_commands.json
|
|||||||
.cache
|
.cache
|
||||||
build
|
build
|
||||||
.clangd
|
.clangd
|
||||||
|
cmake-build-*
|
||||||
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
2
.idea/advent.iml
generated
Normal file
2
.idea/advent.iml
generated
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/advent.iml" filepath="$PROJECT_DIR$/.idea/advent.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/lib/libflint" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,6 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ void advent2015day02(void) {
|
|||||||
t = strtok(NULL, "x");
|
t = strtok(NULL, "x");
|
||||||
int h = atoi(t);
|
int h = atoi(t);
|
||||||
|
|
||||||
paper += 2*l*w + 2*w*h + 2*h*l + int_min(w*l, int_min(l*h, h*w));
|
paper += 2 * l * w + 2 * w * h + 2 * h * l + int_min(w * l, int_min(l * h, h * w));
|
||||||
ribbon += l*w*h + int_min(w+w+h+h, int_min(h+h+l+l, l+l+w+w));
|
ribbon += l * w * h + int_min(w + w + h + h, int_min(h + h + l + l, l + l + w + w));
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d\n%d\n", paper, ribbon);
|
printf("%d\n%d\n", paper, ribbon);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "set.h"
|
#include "set.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
@ -11,7 +10,7 @@ static int part_two(char *input) {
|
|||||||
int *x, *y;
|
int *x, *y;
|
||||||
char *c = input;
|
char *c = input;
|
||||||
|
|
||||||
Set* houses = malloc(sizeof(Set));
|
Set *houses = malloc(sizeof(Set));
|
||||||
set_init(houses, same_Point_v, free);
|
set_init(houses, same_Point_v, free);
|
||||||
|
|
||||||
while (*c != '\0') {
|
while (*c != '\0') {
|
||||||
@ -25,16 +24,24 @@ static int part_two(char *input) {
|
|||||||
is_santa = is_santa == 1 ? 0 : 1;
|
is_santa = is_santa == 1 ? 0 : 1;
|
||||||
|
|
||||||
switch (*c) {
|
switch (*c) {
|
||||||
case '^': ++(*y); break;
|
case '^':
|
||||||
case 'v': --(*y); break;
|
++(*y);
|
||||||
case '>': ++(*x); break;
|
break;
|
||||||
case '<': --(*x); break;
|
case 'v':
|
||||||
|
--(*y);
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
++(*x);
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
--(*x);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
set_insert(houses, (void *) new_Point_p(*x, *y));
|
set_insert(houses, (void *) new_Point_p(*x, *y));
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sz = (int)houses->size;
|
int sz = (int) houses->size;
|
||||||
set_destroy(houses);
|
set_destroy(houses);
|
||||||
|
|
||||||
return sz;
|
return sz;
|
||||||
@ -44,21 +51,29 @@ static int part_one(char *input) {
|
|||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
char *c = input;
|
char *c = input;
|
||||||
|
|
||||||
Set* houses = malloc(sizeof(Set));
|
Set *houses = malloc(sizeof(Set));
|
||||||
set_init(houses, same_Point_v, free);
|
set_init(houses, same_Point_v, free);
|
||||||
|
|
||||||
while (*c != '\0') {
|
while (*c != '\0') {
|
||||||
switch (*c) {
|
switch (*c) {
|
||||||
case '^': ++y; break;
|
case '^':
|
||||||
case 'v': --y; break;
|
++y;
|
||||||
case '>': ++x; break;
|
break;
|
||||||
case '<': --x; break;
|
case 'v':
|
||||||
|
--y;
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
++x;
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
--x;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
set_insert(houses, (void *) new_Point_p(x, y));
|
set_insert(houses, (void *) new_Point_p(x, y));
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sz = (int)houses->size;
|
int sz = (int) houses->size;
|
||||||
set_destroy(houses);
|
set_destroy(houses);
|
||||||
|
|
||||||
return sz;
|
return sz;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user