Skip to content

Commit 66de3a9

Browse files
author
Pascal Guenther
committed
2024 Day 01
0 parents  commit 66de3a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3113
-0
lines changed

.github/workflows/ci-2024-cpp.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: CI AOC2024 C++
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-22.04, windows-2022, macos-12]
15+
compiler: [gnu, msvc, clang]
16+
arch: [x86, x64]
17+
18+
exclude:
19+
- os: ubuntu-22.04
20+
compiler: msvc
21+
22+
- os: macos-12
23+
compiler: msvc
24+
25+
- os: macos-12
26+
compiler: gnu
27+
28+
- os: macos-12
29+
arch: x86
30+
31+
- os: ubuntu-22.04
32+
arch: x86
33+
34+
- os: windows-2022
35+
compiler: gnu
36+
37+
- os: windows-2022
38+
compiler: clang
39+
40+
include:
41+
- os: ubuntu-22.04
42+
nproc: "-j$(nproc)"
43+
mkdir_force: -p
44+
45+
- os: windows-2022
46+
nproc: -j4
47+
mkdir_force: -Force
48+
49+
- os: macos-12
50+
nproc: "-j$(sysctl -n hw.ncpu)"
51+
mkdir_force: -p
52+
53+
- compiler: gnu
54+
cc: gcc-12
55+
cxx: g++-12
56+
ccmac: gcc-12
57+
cxxmac: g++-12
58+
59+
- compiler: clang
60+
cc: clang-14
61+
cxx: clang++-14
62+
ccmac: clang
63+
cxxmac: clang++
64+
65+
- compiler: msvc
66+
cc: cl
67+
cxx: cl
68+
69+
- arch: x86
70+
archWin: -A Win32
71+
archLin: -m32
72+
73+
- arch: x64
74+
archWin: -A x64
75+
76+
env:
77+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
78+
BUILD_TYPE: Debug
79+
80+
81+
steps:
82+
- uses: actions/checkout@v2
83+
84+
- name: Configure CMake for Linux
85+
if: runner.os == 'Linux'
86+
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{ matrix.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx }}
87+
88+
- name: Configure CMake for Windows
89+
if: runner.os == 'Windows'
90+
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -G "Visual Studio 17 2024" ${{ matrix.archWin }}
91+
92+
- name: Configure CMake for macOS
93+
if: runner.os == 'macOS'
94+
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{ matrix.ccmac }} -DCMAKE_CXX_COMPILER=${{ matrix.cxxmac }}
95+
96+
- name: Build
97+
# Build your program with the given configuration
98+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} ${{ matrix.nproc }}
99+
100+
- name: Test
101+
working-directory: ${{github.workspace}}/build
102+
# Execute tests defined by the CMake configuration.
103+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
104+
run: ctest ${{ matrix.nproc }} -C ${{env.BUILD_TYPE}}

.github/workflows/codeql.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "main" ]
20+
schedule:
21+
- cron: '16 19 * * 1'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'cpp' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Use only 'java' to analyze code written in Java, Kotlin or both
38+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
39+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v3
44+
45+
# Initializes the CodeQL tools for scanning.
46+
- name: Initialize CodeQL
47+
uses: github/codeql-action/init@v2
48+
with:
49+
languages: ${{ matrix.language }}
50+
# If you wish to specify custom queries, you can do so here or in a config file.
51+
# By default, queries listed here will override any specified in a config file.
52+
# Prefix the list here with "+" to use these queries and those in the config file.
53+
54+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
55+
# queries: security-extended,security-and-quality
56+
57+
58+
# Autobuild attempts to build any compiled (C/C++, C#, Go, or Java).
59+
# If this step fails, then you should remove it and run the build manually (see below)
60+
- name: Autobuild
61+
uses: github/codeql-action/autobuild@v2
62+
63+
# ℹ️ Command-line programs to run using the OS shell.
64+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
65+
66+
# If the Autobuild fails above, remove it and uncomment the following three lines.
67+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
68+
69+
# - run: |
70+
# echo "Run, Build Application using script"
71+
# ./location_of_script_within_repo/buildscript.sh
72+
73+
- name: Perform CodeQL Analysis
74+
uses: github/codeql-action/analyze@v2
75+
with:
76+
category: "/language:${{matrix.language}}"

.github/workflows/flawfinder.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: flawfinder
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
# The branches below must be a subset of the branches above
13+
branches: [ "main" ]
14+
schedule:
15+
- cron: '22 5 * * 1'
16+
17+
jobs:
18+
flawfinder:
19+
name: Flawfinder
20+
runs-on: ubuntu-latest
21+
permissions:
22+
actions: read
23+
contents: read
24+
security-events: write
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v3
28+
29+
- name: flawfinder_scan
30+
uses: david-a-wheeler/flawfinder@8e4a779ad59dbfaee5da586aa9210853b701959c
31+
with:
32+
arguments: '--sarif ./'
33+
output: 'flawfinder_results.sarif'
34+
35+
- name: Upload analysis results to GitHub Security tab
36+
uses: github/codeql-action/upload-sarif@v2
37+
with:
38+
sarif_file: ${{github.workspace}}/flawfinder_results.sarif

.github/workflows/msvc.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
#
6+
# Find more information at:
7+
# https://github.com/microsoft/msvc-code-analysis-action
8+
9+
name: Microsoft C++ Code Analysis
10+
11+
on:
12+
push:
13+
branches: [ "main" ]
14+
pull_request:
15+
branches: [ "main" ]
16+
17+
env:
18+
# Path to the CMake build directory.
19+
build: '${{ github.workspace }}/build'
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
analyze:
26+
permissions:
27+
contents: read # for actions/checkout to fetch code
28+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
29+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
30+
name: Analyze
31+
runs-on: windows-latest
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v3
36+
37+
- name: Configure CMake
38+
run: cmake -B ${{ env.build }} -DAOC_TESTING=Off
39+
40+
# Build is not required unless generated source files are used
41+
# - name: Build CMake
42+
# run: cmake --build ${{ env.build }}
43+
44+
- name: Initialize MSVC Code Analysis
45+
uses: microsoft/msvc-code-analysis-action@04825f6d9e00f87422d6bf04e1a38b1f3ed60d99
46+
# Provide a unique ID to access the sarif output path
47+
id: run-analysis
48+
with:
49+
cmakeBuildDirectory: ${{ env.build }}
50+
# Ruleset file that will determine what checks will be run
51+
ruleset: NativeRecommendedRules.ruleset
52+
53+
# Upload SARIF file to GitHub Code Scanning Alerts
54+
- name: Upload SARIF to GitHub
55+
uses: github/codeql-action/upload-sarif@v2
56+
with:
57+
sarif_file: ${{ steps.run-analysis.outputs.sarif }}
58+
59+
# Upload SARIF file as an Artifact to download and view
60+
# - name: Upload SARIF as an Artifact
61+
# uses: actions/upload-artifact@v3
62+
# with:
63+
# name: sarif-file
64+
# path: ${{ steps.run-analysis.outputs.sarif }}

.github/workflows/webapp.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Deploy-Webapp
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-and-deploy:
9+
runs-on: ubuntu-22.04
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: install emscripten
15+
run: git clone https://github.com/emscripten-core/emsdk.git && emsdk/emsdk install latest && emsdk/emsdk activate latest && source emsdk/emsdk_env.sh
16+
17+
- name: Configure CMake
18+
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=On -DCMAKE_TOOLCHAIN_FILE=emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
19+
20+
- name: Build
21+
# Build your program with the given configuration
22+
run: cmake --build ${{github.workspace}}/build --target aoc-2024-web -j8
23+
24+
- name: Deploy webapp to Github pages
25+
uses: JamesIves/[email protected]
26+
with:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
BRANCH: gh-pages
29+
FOLDER: build/bin/aoc-2024-www
30+

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build*/
2+
**/build/
3+
**/out
4+
**/.DS_Store
5+
**/.vs
6+
**/.vscode
7+
.venv/

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(AdventOfCode VERSION 2024.12.01)
4+
5+
option(AOC_TESTING "Enable testing for AdventOfCode" On)
6+
7+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
8+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
9+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
10+
11+
if(AOC_TESTING)
12+
enable_testing()
13+
endif()
14+
15+
add_subdirectory(cpp)

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Advent of Code FF
2+
[Advent of Code 2024](https://adventofcode.com/2024)
3+
4+
## C++
5+
C++20 solutions for advent of code 2024.
6+
7+
### Variants
8+
9+
- [Web application](https://pascalguenther.github.io/AdventOfCode2024/)
10+
C++ code is compiled into WebAssembly, which can be executed by the browser. The static webpage is hosted on Github pages. Supports drag&drop for files. Input can be edited and result will update live. You could call it an Advent-of-Code-REPL 😎
11+
CMake target: `aoc-2024-web`. Compile with emscripten (see [GitHub action file](/Users/pascal/repos/adventOfCode2024/.github/workflows/webapp.yml) for an example)
12+
- Command line application
13+
A standard command line application, which expects the day and the path to the input file as parameters.
14+
CMake target: `aoc-2024-web`
15+
16+
17+
### Features
18+
- low memory usage
19+
- good performance
20+
- most puzzle solutions are `constexpr`, thus, they can be validated using `static_assert` (on some modern compilers, at least)
21+
- except for day 12, since it uses `std::set`which is not yet `constexpr`-enabled in C++20
22+
- [Compile-time regular expressions (`ctre`)](https://github.com/hanickadot/compile-time-regular-expressions) for input validation
23+
- unit testing (with example inputs)
24+
25+
### Supported compilers
26+
- Visual Studio 2022
27+
- gcc 12 or higher
28+
- clang 14 or higher
29+
30+
### Building the command line application
31+
Either, open the directory directly in VisualStudio,
32+
or run
33+
- Configure CMake: `cmake -S . -B build`
34+
- Build the project
35+
- only the main program: `cmake --build build --target aoc-2024-cli`
36+
- or, build everything: `cmake --build build`
37+
- Run a specific day (Example: Day 01): `build/bin/aoc-2024-cli 01 2024/input/day01.txt`

cpp/.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
4+
...

cpp/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vs/
2+
.vscode/
3+
.settings/
4+
build/
5+
.DS_Store

0 commit comments

Comments
 (0)