diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f1fdf64 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# \file .editorconfig +# \author Copyright 2020, Matthew Gretton-Dann +# SPDX-License-Identifier: Apache-2.0 + +# top-most EditorConfig file +root = true + +# We default to 2-spaces at tabs +[*] +indent_style = space +indent_size = 2 +tab_width = 8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 100 + +# Python is 4 spaces +[*.py] +indent_size = 4 +max_line_length = 79 + +# Makefiles use Tabs. +[Makefile] +indent_style = tab diff --git a/CMakeLists.txt b/CMakeLists.txt index e51380b..afd0ef3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,17 +5,19 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -file(GLOB years LIST_DIRECTORIES true RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "20[1-9][0-9]") +file(GLOB years LIST_DIRECTORIES true RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS + "20[1-9][0-9]") message(STATUS "Years to examine: ${years}") -foreach(year IN LISTS years) - file(GLOB puzzles RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "${year}/puzzle-*.cc") - foreach(puzzle IN LISTS puzzles) - string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" "puzzle-${year}-\\1" puzzle_name "${puzzle}") - string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" "${CMAKE_SOURCE_DIR}/${year}/puzzle-\\1.CMakeLists.txt" sub_cmake_lists "${puzzle}") - message(STATUS "Puzzle: ${puzzle_name} - source ${puzzle}") - add_executable("${puzzle_name}" "${puzzle}") - if(EXISTS "${sub_cmake_lists}") - include("${sub_cmake_lists}") - endif() - endforeach() -endforeach() \ No newline at end of file +foreach (year IN LISTS years) + file(GLOB puzzles RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "${year}/puzzle-*.cc") + foreach (puzzle IN LISTS puzzles) + string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" "puzzle-${year}-\\1" puzzle_name "${puzzle}") + string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" + "${CMAKE_SOURCE_DIR}/${year}/puzzle-\\1.CMakeLists.txt" sub_cmake_lists "${puzzle}") + message(STATUS "Puzzle: ${puzzle_name} - source ${puzzle}") + add_executable("${puzzle_name}" "${puzzle}") + if (EXISTS "${sub_cmake_lists}") + include("${sub_cmake_lists}") + endif () + endforeach () +endforeach () diff --git a/README.md b/README.md index a74590f..77bfec9 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # C++ Solutions to Advent of Code -This repository contains solutions to various years of the [Advent of Code](https://adventofcode.com) -puzzles. All solutions are written in C++. The solutions aren't designed to be nice or -pretty. Instead, I am using it as an experiment in understanding how I approach solving -problems. +This repository contains solutions to various years of +the [Advent of Code](https://adventofcode.com) +puzzles. All solutions are written in C++. The solutions aren't designed to be nice or pretty. +Instead, I am using it as an experiment in understanding how I approach solving problems. -The solutions are authored by Matthew Gretton-Dann, and Copyright 2020-2021, Matthew Gretton-Dann. Licensed under Apache 2.0 - see [license](./LICENSE). +The solutions are authored by Matthew Gretton-Dann, and Copyright 2020-2021, Matthew Gretton-Dann. +Licensed under Apache 2.0 - see [license](./LICENSE). ## Getting the sources @@ -19,14 +20,14 @@ git clone https://github.com/matt-gretton-dann/advent-of-code/ The following is required to build the puzzles: - * CMake - * C++20 compiler - * OpenSSL headers. +* CMake +* C++20 compiler +* OpenSSL headers. ## Running the Puzzles -There is a driver script (`./driver.sh`) in the root of the checkout. It will build and run specific tests. Example -use is as follows: +There is a driver script (`./driver.sh`) in the root of the checkout. It will build and run specific +tests. Example use is as follows: ```sh YEAR=2020 # Year of puzzle to run @@ -45,7 +46,10 @@ cmake -Bbuild -S. cmake --build build ``` -Note that some of the puzzles require OpenSSL for the MD5 implementation. On macOS this also requires you to pass an appropariate value for `OPENSSL_ROOT_DIR` to cmake. On x86 this is `-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl` and on AArch64 this is `-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl`. +**Note**: Some puzzles require OpenSSL for the MD5 implementation. On macOS this requires you to +pass an appropriate value for `OPENSSL_ROOT_DIR` to `cmake`. If using `homebrew` then x86 this +is `-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl` and on AArch64 this +is `-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl`. ## Sources @@ -53,19 +57,20 @@ All code is written in C++. ### Directory Layout -Each year of puzzles is in a self-contained directory `YEAR`. +Each year of puzzles is in a self-contained directory `YEAR`. Within the directory there are the following files: - * `puzzle-DAY-NUMBER.cc`. The source for puzzle NUMBER on day DAY in the year. - * `driver-DAY-NUMBER.sh`. If present this is used as the driver to run that puzzle. - * `puzzle-DAY-NUMBER.CMakeLists.txt`. If present this is included by `CMakeLists.txt`. The variable `${puzzle_name}` - contains the name of the puzzle target. Some puzzles use this to depend on OpenSSL. +* `puzzle-DAY-NUMBER.cc`. The source for puzzle NUMBER on DAY in the year. +* `driver-DAY-NUMBER.sh`. If present this is used as the driver to run that puzzle. +* `puzzle-DAY-NUMBER.CMakeLists.txt`. If present this is included by `CMakeLists.txt`. The + variable `${puzzle_name}` + contains the name of the puzzle target. Some puzzles use this to depend on OpenSSL. ### Command Line Interface The executable command line interface should just take the input in on standard-input and print its result on standard-output. -If this is not possible the script `driver-DAY-NUMBER.sh` within the year directory should be provided. It should take -two arguments - the executable to run and the input file to use. \ No newline at end of file +If this is not possible the script `driver-DAY-NUMBER.sh` within the year directory should be +provided. It should take two arguments - the executable to run and the input file to use. diff --git a/driver.sh b/driver.sh index 50be12e..c696f91 100755 --- a/driver.sh +++ b/driver.sh @@ -44,8 +44,8 @@ fi # Rebuild the executable we want to run. if [ ! -d "build" ]; then opts= - if [ "$(uname -s)" == "Darwin" ]; then - if [ "$(uname -m)" == "arm64" ]; then + if [ "$(uname -s)" = "Darwin" ]; then + if [ "$(uname -m)" = "arm64" ]; then opts="-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl" else opts="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl"