Add .editorconfig

This commit is contained in:
2021-12-02 07:15:35 +00:00
parent d9e1d2cf89
commit e58dede1b6
4 changed files with 64 additions and 33 deletions

24
.editorconfig Normal file
View File

@@ -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

View File

@@ -5,17 +5,19 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) 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}") message(STATUS "Years to examine: ${years}")
foreach(year IN LISTS years) foreach (year IN LISTS years)
file(GLOB puzzles RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "${year}/puzzle-*.cc") file(GLOB puzzles RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "${year}/puzzle-*.cc")
foreach(puzzle IN LISTS puzzles) foreach (puzzle IN LISTS puzzles)
string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" "puzzle-${year}-\\1" puzzle_name "${puzzle}") 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}") string(REGEX REPLACE "^.*puzzle-(.*)\\.cc"
message(STATUS "Puzzle: ${puzzle_name} - source ${puzzle}") "${CMAKE_SOURCE_DIR}/${year}/puzzle-\\1.CMakeLists.txt" sub_cmake_lists "${puzzle}")
add_executable("${puzzle_name}" "${puzzle}") message(STATUS "Puzzle: ${puzzle_name} - source ${puzzle}")
if(EXISTS "${sub_cmake_lists}") add_executable("${puzzle_name}" "${puzzle}")
include("${sub_cmake_lists}") if (EXISTS "${sub_cmake_lists}")
endif() include("${sub_cmake_lists}")
endforeach() endif ()
endforeach() endforeach ()
endforeach ()

View File

@@ -1,11 +1,12 @@
# C++ Solutions to Advent of Code # C++ Solutions to Advent of Code
This repository contains solutions to various years of the [Advent of Code](https://adventofcode.com) This repository contains solutions to various years of
puzzles. All solutions are written in C++. The solutions aren't designed to be nice or the [Advent of Code](https://adventofcode.com)
pretty. Instead, I am using it as an experiment in understanding how I approach solving puzzles. All solutions are written in C++. The solutions aren't designed to be nice or pretty.
problems. 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 ## 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: The following is required to build the puzzles:
* CMake * CMake
* C++20 compiler * C++20 compiler
* OpenSSL headers. * OpenSSL headers.
## Running the Puzzles ## Running the Puzzles
There is a driver script (`./driver.sh`) in the root of the checkout. It will build and run specific tests. Example There is a driver script (`./driver.sh`) in the root of the checkout. It will build and run specific
use is as follows: tests. Example use is as follows:
```sh ```sh
YEAR=2020 # Year of puzzle to run YEAR=2020 # Year of puzzle to run
@@ -45,7 +46,10 @@ cmake -Bbuild -S.
cmake --build build 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 ## Sources
@@ -53,19 +57,20 @@ All code is written in C++.
### Directory Layout ### 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: Within the directory there are the following files:
* `puzzle-DAY-NUMBER.cc`. The source for puzzle NUMBER on day DAY in the year. * `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. * `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}` * `puzzle-DAY-NUMBER.CMakeLists.txt`. If present this is included by `CMakeLists.txt`. The
contains the name of the puzzle target. Some puzzles use this to depend on OpenSSL. variable `${puzzle_name}`
contains the name of the puzzle target. Some puzzles use this to depend on OpenSSL.
### Command Line Interface ### Command Line Interface
The executable command line interface should just take the input in on standard-input and print its The executable command line interface should just take the input in on standard-input and print its
result on standard-output. 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 If this is not possible the script `driver-DAY-NUMBER.sh` within the year directory should be
two arguments - the executable to run and the input file to use. provided. It should take two arguments - the executable to run and the input file to use.

View File

@@ -44,8 +44,8 @@ fi
# Rebuild the executable we want to run. # Rebuild the executable we want to run.
if [ ! -d "build" ]; then if [ ! -d "build" ]; then
opts= opts=
if [ "$(uname -s)" == "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -m)" == "arm64" ]; then if [ "$(uname -m)" = "arm64" ]; then
opts="-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl" opts="-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl"
else else
opts="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl" opts="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl"