Code cleanup
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -4,3 +4,4 @@ compile_commands.json
 | 
			
		||||
.cache
 | 
			
		||||
build
 | 
			
		||||
.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,29 +1,28 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "input.h"
 | 
			
		||||
 | 
			
		||||
void advent2015day01(void) {
 | 
			
		||||
  char *input = get_input("input/2015/01");
 | 
			
		||||
  char *c = input;
 | 
			
		||||
  int f = 0, b = 0, s = 1;
 | 
			
		||||
    char *input = get_input("input/2015/01");
 | 
			
		||||
    char *c = input;
 | 
			
		||||
    int f = 0, b = 0, s = 1;
 | 
			
		||||
 | 
			
		||||
  while (*c != '\0') {
 | 
			
		||||
    if (*c == '(') {
 | 
			
		||||
      ++f;
 | 
			
		||||
    } else {
 | 
			
		||||
      --f;
 | 
			
		||||
    while (*c != '\0') {
 | 
			
		||||
        if (*c == '(') {
 | 
			
		||||
            ++f;
 | 
			
		||||
        } else {
 | 
			
		||||
            --f;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (f == -1 && b == 0) {
 | 
			
		||||
            b = s;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ++c;
 | 
			
		||||
        ++s;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (f == -1 && b == 0) {
 | 
			
		||||
      b = s;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ++c;
 | 
			
		||||
    ++s;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  printf("%d\n%d\n", f, b);
 | 
			
		||||
  free(input);
 | 
			
		||||
    printf("%d\n%d\n", f, b);
 | 
			
		||||
    free(input);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,22 +6,22 @@
 | 
			
		||||
#include "advent_math.h"
 | 
			
		||||
 | 
			
		||||
void advent2015day02(void) {
 | 
			
		||||
  size_t sz = 0;
 | 
			
		||||
  char **lines = get_lines("input/2015/02", &sz);
 | 
			
		||||
  int paper = 0, ribbon = 0;
 | 
			
		||||
    size_t sz = 0;
 | 
			
		||||
    char **lines = get_lines("input/2015/02", &sz);
 | 
			
		||||
    int paper = 0, ribbon = 0;
 | 
			
		||||
 | 
			
		||||
  for (size_t i = 0; i < sz; i++) {
 | 
			
		||||
    char *t = strtok(lines[i], "x");
 | 
			
		||||
    int w = atoi(t);
 | 
			
		||||
    t = strtok(NULL, "x");
 | 
			
		||||
    int l = atoi(t);
 | 
			
		||||
    t = strtok(NULL, "x");
 | 
			
		||||
    int h = atoi(t);
 | 
			
		||||
    for (size_t i = 0; i < sz; i++) {
 | 
			
		||||
        char *t = strtok(lines[i], "x");
 | 
			
		||||
        int w = atoi(t);
 | 
			
		||||
        t = strtok(NULL, "x");
 | 
			
		||||
        int l = atoi(t);
 | 
			
		||||
        t = strtok(NULL, "x");
 | 
			
		||||
        int h = atoi(t);
 | 
			
		||||
 | 
			
		||||
    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));
 | 
			
		||||
  }
 | 
			
		||||
        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));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  printf("%d\n%d\n", paper, ribbon);
 | 
			
		||||
  del_lines(lines);
 | 
			
		||||
    printf("%d\n%d\n", paper, ribbon);
 | 
			
		||||
    del_lines(lines);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "set.h"
 | 
			
		||||
#include "input.h"
 | 
			
		||||
@@ -11,7 +10,7 @@ static int part_two(char *input) {
 | 
			
		||||
    int *x, *y;
 | 
			
		||||
    char *c = input;
 | 
			
		||||
 | 
			
		||||
    Set* houses = malloc(sizeof(Set));
 | 
			
		||||
    Set *houses = malloc(sizeof(Set));
 | 
			
		||||
    set_init(houses, same_Point_v, free);
 | 
			
		||||
 | 
			
		||||
    while (*c != '\0') {
 | 
			
		||||
@@ -25,16 +24,24 @@ static int part_two(char *input) {
 | 
			
		||||
        is_santa = is_santa == 1 ? 0 : 1;
 | 
			
		||||
 | 
			
		||||
        switch (*c) {
 | 
			
		||||
        case '^': ++(*y); break;
 | 
			
		||||
        case 'v': --(*y); break;
 | 
			
		||||
        case '>': ++(*x); break;
 | 
			
		||||
        case '<': --(*x); break;
 | 
			
		||||
        case '^':
 | 
			
		||||
            ++(*y);
 | 
			
		||||
            break;
 | 
			
		||||
        case 'v':
 | 
			
		||||
            --(*y);
 | 
			
		||||
            break;
 | 
			
		||||
        case '>':
 | 
			
		||||
            ++(*x);
 | 
			
		||||
            break;
 | 
			
		||||
        case '<':
 | 
			
		||||
            --(*x);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        set_insert(houses, (void *) new_Point_p(*x, *y));
 | 
			
		||||
        ++c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int sz = (int)houses->size;
 | 
			
		||||
    int sz = (int) houses->size;
 | 
			
		||||
    set_destroy(houses);
 | 
			
		||||
 | 
			
		||||
    return sz;
 | 
			
		||||
@@ -44,31 +51,39 @@ static int part_one(char *input) {
 | 
			
		||||
    int x = 0, y = 0;
 | 
			
		||||
    char *c = input;
 | 
			
		||||
 | 
			
		||||
    Set* houses = malloc(sizeof(Set));
 | 
			
		||||
    Set *houses = malloc(sizeof(Set));
 | 
			
		||||
    set_init(houses, same_Point_v, free);
 | 
			
		||||
 | 
			
		||||
    while (*c != '\0') {
 | 
			
		||||
        switch (*c) {
 | 
			
		||||
        case '^': ++y; break;
 | 
			
		||||
        case 'v': --y; break;
 | 
			
		||||
        case '>': ++x; break;
 | 
			
		||||
        case '<': --x; break;
 | 
			
		||||
        case '^':
 | 
			
		||||
            ++y;
 | 
			
		||||
            break;
 | 
			
		||||
        case 'v':
 | 
			
		||||
            --y;
 | 
			
		||||
            break;
 | 
			
		||||
        case '>':
 | 
			
		||||
            ++x;
 | 
			
		||||
            break;
 | 
			
		||||
        case '<':
 | 
			
		||||
            --x;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        set_insert(houses, (void *) new_Point_p(x, y));
 | 
			
		||||
        ++c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int sz = (int)houses->size;
 | 
			
		||||
    int sz = (int) houses->size;
 | 
			
		||||
    set_destroy(houses);
 | 
			
		||||
 | 
			
		||||
    return sz;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void advent2015day03(void) {
 | 
			
		||||
  char *input = get_input("input/2015/03");
 | 
			
		||||
    char *input = get_input("input/2015/03");
 | 
			
		||||
 | 
			
		||||
  printf("%d\n", part_one(input));
 | 
			
		||||
  printf("%d\n", part_two(input));
 | 
			
		||||
    printf("%d\n", part_one(input));
 | 
			
		||||
    printf("%d\n", part_two(input));
 | 
			
		||||
 | 
			
		||||
  free(input);
 | 
			
		||||
    free(input);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,46 +6,46 @@
 | 
			
		||||
#include "advent_utility.h"
 | 
			
		||||
 | 
			
		||||
static int is_five(char *test) {
 | 
			
		||||
  char *t = test;
 | 
			
		||||
  for (int i = 0; i < 5; ++i, ++t) {
 | 
			
		||||
    if (*t != '0') {
 | 
			
		||||
      return 0;
 | 
			
		||||
    char *t = test;
 | 
			
		||||
    for (int i = 0; i < 5; ++i, ++t) {
 | 
			
		||||
        if (*t != '0') {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return 1;
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int is_six(char *test) {
 | 
			
		||||
  char *t = test;
 | 
			
		||||
  for (int i = 0; i < 6; ++i, ++t) {
 | 
			
		||||
    if (*t != '0') {
 | 
			
		||||
      return 0;
 | 
			
		||||
    char *t = test;
 | 
			
		||||
    for (int i = 0; i < 6; ++i, ++t) {
 | 
			
		||||
        if (*t != '0') {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return 1;
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void advent2015day04(void) {
 | 
			
		||||
  char *input = get_input("input/2015/04");
 | 
			
		||||
  int c = 0, five = 0, six = 0;
 | 
			
		||||
    char *input = get_input("input/2015/04");
 | 
			
		||||
    int c = 0, five = 0, six = 0;
 | 
			
		||||
 | 
			
		||||
  while (!five || !six) {
 | 
			
		||||
    char test[strlen(input) + 8];
 | 
			
		||||
    sprintf(test, "%s%d", input, c);
 | 
			
		||||
    char *md5 = md5_str(test);
 | 
			
		||||
    while (!five || !six) {
 | 
			
		||||
        char test[strlen(input) + 8];
 | 
			
		||||
        sprintf(test, "%s%d", input, c);
 | 
			
		||||
        char *md5 = md5_str(test);
 | 
			
		||||
 | 
			
		||||
    if (!five && is_five(md5)) {
 | 
			
		||||
      five = c;
 | 
			
		||||
      printf("%d\n", five);
 | 
			
		||||
    }
 | 
			
		||||
    if (is_six(md5)) {
 | 
			
		||||
      six = c;
 | 
			
		||||
        if (!five && is_five(md5)) {
 | 
			
		||||
            five = c;
 | 
			
		||||
            printf("%d\n", five);
 | 
			
		||||
        }
 | 
			
		||||
        if (is_six(md5)) {
 | 
			
		||||
            six = c;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        free(md5);
 | 
			
		||||
        ++c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    free(md5);
 | 
			
		||||
    ++c;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  printf("%d\n", six);
 | 
			
		||||
  free(input);
 | 
			
		||||
    printf("%d\n", six);
 | 
			
		||||
    free(input);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user