From 94d3ffe921b1dfae165902f16b49cbcec150574f Mon Sep 17 00:00:00 2001 From: Pratchaya Khansomboon Date: Mon, 2 Dec 2024 14:41:42 +0100 Subject: [PATCH] aoc24: day01 update to zip Include Linux command stuff to use clang compiler. --- README.md | 6 ++++++ aoc.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 33e7db8..823f762 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ Symlink `compile_commands.json` to root directory for `ccls`/`clangd`. ln -sfn ./build/compile_commands.json . ``` +**Linux (use clang)** + +```sh +CC=clang CXX=clang++ cmake -S . -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-stdlib=libc++ -I$HOME/.local/include/c++/v1" -DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++ -fuse-ld=lld -L$HOME/.local/lib" -DCMAKE_SHARED_LINKER_FLAGS="-stdlib=libc++ -fuse-ld=lld -L$HOME/.local/lib" +``` + **Windows (requires admin)** ```sh diff --git a/aoc.cpp b/aoc.cpp index e1517d9..b45031c 100644 --- a/aoc.cpp +++ b/aoc.cpp @@ -48,11 +48,12 @@ auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int { std::sort(std::begin(a), std::end(a)); std::sort(std::begin(b), std::end(b)); - auto diff_view = std::views::zip_transform([](auto a, auto b) { - return a > b ? a - b : b - a; - }, a, b); - + auto diff_view = std::views::zip(a, b) | std::views::transform([](auto const& p) { + auto const [x, y] = p; + return x > y ? x - y : y - x; + }); auto const sum = std::accumulate(std::begin(diff_view), std::end(diff_view), 0); + fmt::print("Part A: {}\n", std::abs(sum)); auto values = a | std::views::transform([&b](auto v) {