2015-05
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +1,3 @@
 | 
				
			|||||||
[submodule "lib/libflint"]
 | 
					[submodule "lib/libflint"]
 | 
				
			||||||
	path = lib/libflint
 | 
						path = lib/libflint
 | 
				
			||||||
	url = git@git.fputs.com:fputs/libflint
 | 
						url = https://fputs.com/fputs/libflint
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,10 +7,15 @@ struct Point {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Point new_Point(int, int);
 | 
					struct Point new_Point(int, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Point *new_Point_p(int, int);
 | 
					struct Point *new_Point_p(int, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int same_Point(const struct Point *, const struct Point *);
 | 
					int same_Point(const struct Point *, const struct Point *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int same_Point_v(const void *, const void *);
 | 
					int same_Point_v(const void *, const void *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *md5_str(const char *);
 | 
					char *md5_str(const char *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *capture_system(const char *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,16 @@
 | 
				
			|||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "input.h"
 | 
					#include "advent_utility.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void advent2015day05(void) {
 | 
					void advent2015day05(void) {
 | 
				
			||||||
  char *input = get_input("input/2015/05");
 | 
					    /* Sometimes, grep really is the best tool */
 | 
				
			||||||
  printf("Solution for Day 05 of 2015 is not completed yet\n");
 | 
					    char *p1 = capture_system(
 | 
				
			||||||
  free(input);
 | 
					            "grep -E \"(.*[aeiou]){3}\" ./input/2015/05 | grep \"\\(.\\)\\1\" | egrep -v \"(ab|cd|pq|xy)\" | wc -l");
 | 
				
			||||||
 | 
					    char *p2 = capture_system("grep \"\\(..\\).*\\1\" ./input/2015/05 | grep \"\\(.\\).\\1\" | wc -l");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf("%s%s", p1, p2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    free(p1);
 | 
				
			||||||
 | 
					    free(p2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,14 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __linux__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openssl/md5.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
#include <md5.h>
 | 
					#include <md5.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "advent_utility.h"
 | 
					#include "advent_utility.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -32,13 +39,33 @@ int same_Point_v(const void *a, const void *b) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
char *md5_str(const char *input) {
 | 
					char *md5_str(const char *input) {
 | 
				
			||||||
    unsigned char digest[16];
 | 
					    unsigned char digest[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __linux__
 | 
				
			||||||
 | 
					    MD5_CTX context;
 | 
				
			||||||
 | 
					    MD5_Init(&context);
 | 
				
			||||||
 | 
					    MD5_Update(&context, input, strlen(input));
 | 
				
			||||||
 | 
					    MD5_Final(digest, &context);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
    struct MD5Context context;
 | 
					    struct MD5Context context;
 | 
				
			||||||
    MD5Init(&context);
 | 
					    MD5Init(&context);
 | 
				
			||||||
    MD5Update(&context, input, strlen(input));
 | 
					    MD5Update(&context, input, strlen(input));
 | 
				
			||||||
    MD5Final(digest, &context);
 | 
					    MD5Final(digest, &context);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char *md5string = malloc(33);
 | 
					    char *md5string = malloc(33);
 | 
				
			||||||
    for (int i = 0; i < 16; ++i) {
 | 
					    for (int i = 0; i < 16; ++i) {
 | 
				
			||||||
        sprintf(&md5string[i * 2], "%02x", (unsigned int) digest[i]);
 | 
					        sprintf(&md5string[i * 2], "%02x", (unsigned int) digest[i]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return md5string;
 | 
					    return md5string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *capture_system(const char *cmd) {
 | 
				
			||||||
 | 
					    char *buf = malloc(256);
 | 
				
			||||||
 | 
					    FILE *tmp = popen(cmd, "r");
 | 
				
			||||||
 | 
					    if (tmp == NULL) {
 | 
				
			||||||
 | 
					        printf("failed to open FILE *tmp\n");
 | 
				
			||||||
 | 
					        exit(1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    fgets(buf, 256, tmp);
 | 
				
			||||||
 | 
					    return buf;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user