update for macOS, 2015-08
This commit is contained in:
parent
597db66495
commit
b0b6773395
@ -20,12 +20,20 @@ file(COPY input DESTINATION ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_executable(advent ${SRC} ${SRC2015} ${SRC2016} ${SRC2017} ${SRC2018} ${SRC2019} ${SRC2020} ${SRC2021})
|
||||
|
||||
if ((${CMAKE_SYSTEM_NAME} STREQUAL "Darwin"))
|
||||
set(OPENSSL_ROOT_DIR /opt/homebrew/opt/openssl@3)
|
||||
endif()
|
||||
|
||||
if ((${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD"))
|
||||
target_link_libraries(advent PRIVATE flint)
|
||||
target_include_directories(advent PRIVATE include lib/libflint/include lib/uthash/src)
|
||||
else()
|
||||
elseif ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux"))
|
||||
find_package(OpenSSL REQUIRED)
|
||||
target_link_libraries(advent PRIVATE bsd flint ${OPENSSL_LIBRARIES})
|
||||
target_include_directories(advent PRIVATE include lib/libflint/include lib/uthash/src ${OpenSSL_INCLUDE_DIR})
|
||||
else() # Basically MacOS/Darwin
|
||||
set(OpenSSL_INCLUDE_DIR /opt/homebrew/opt/openssl@3/include)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
target_link_libraries(advent PRIVATE flint ${OPENSSL_LIBRARIES})
|
||||
target_include_directories(advent PRIVATE include lib/libflint/include lib/uthash/src ${OpenSSL_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
rm -rf input
|
||||
for year in {2015..2021}; do
|
||||
mkdir -p input/$year
|
||||
mkdir -p input/"$year"
|
||||
for day in {1..25}; do
|
||||
if [[ day -lt 10 ]]; then
|
||||
d="0$day"
|
||||
@ -10,7 +10,7 @@ for year in {2015..2021}; do
|
||||
d="$day"
|
||||
fi
|
||||
url="https://adventofcode.com/$year/day/$day/input"
|
||||
curl --cookie "session=$1" $url | perl -pe 'chomp if eof' > input/$year/$d
|
||||
curl --cookie "session=$1" $url | perl -pe 'chomp if eof' > "input/$year/$d"
|
||||
done
|
||||
touch input/$year/test
|
||||
touch "input/$year/test"
|
||||
done
|
||||
|
@ -1,10 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lfinput.h"
|
||||
|
||||
void advent2015day08(void) {
|
||||
char *input = get_input("input/2015/08");
|
||||
printf("Solution for Day 08 of 2015 is not completed yet\n");
|
||||
free(input);
|
||||
static size_t part_one(char** input, size_t sz) {
|
||||
size_t code = 0, mem = 0;
|
||||
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
code += strlen(input[i]);
|
||||
for (size_t j = 1; j < strlen(input[i]) - 1; ++j) {
|
||||
if (input[i][j] == '\\') {
|
||||
if (input[i][j + 1] == '\"' || input[i][j + 1] == '\\') {
|
||||
++j;
|
||||
} else {
|
||||
j += 3;
|
||||
}
|
||||
}
|
||||
++mem;
|
||||
}
|
||||
}
|
||||
|
||||
return code - mem;
|
||||
}
|
||||
|
||||
static size_t part_two(char** input, size_t sz) {
|
||||
size_t code = 0, encoded = 0;
|
||||
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
code += strlen(input[i]);
|
||||
encoded += 6;
|
||||
for (size_t j = 1; j < strlen(input[i]) - 1; ++j) {
|
||||
if (input[i][j] == '\\' || input[i][j] == '\"') {
|
||||
++encoded;
|
||||
}
|
||||
++encoded;
|
||||
}
|
||||
}
|
||||
|
||||
return encoded - code;
|
||||
}
|
||||
|
||||
void advent2015day08(void) {
|
||||
size_t sz = 0;
|
||||
char **input = get_lines("input/2015/08", &sz);
|
||||
|
||||
printf("%zu\n", part_one(input, sz));
|
||||
printf("%zu\n", part_two(input, sz));
|
||||
|
||||
del_lines(input);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#if defined __linux__ || defined __APPLE__
|
||||
|
||||
#include <openssl/md5.h>
|
||||
|
||||
@ -40,7 +40,7 @@ int same_Point_v(const void *a, const void *b) {
|
||||
char *md5_str(const char *input) {
|
||||
unsigned char digest[16];
|
||||
|
||||
#ifdef __linux__
|
||||
#if defined __linux__ || defined __APPLE__
|
||||
MD5_CTX context;
|
||||
MD5_Init(&context);
|
||||
MD5_Update(&context, input, strlen(input));
|
||||
|
Loading…
x
Reference in New Issue
Block a user