diff options
| author | Kleidi Bujari <mail@4kb.net> | 2025-01-24 12:14:23 -0500 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2025-01-24 12:14:23 -0500 |
| commit | 32f4cb5cbba313b7af2fce46139c04d9469cb72a (patch) | |
| tree | 3cc7da05d4320a8f89a726d67811110771dae1bf /mod | |
| parent | 8271e2b89180578ab4dd9ed9eb37142254e5a148 (diff) | |
| download | depot-32f4cb5cbba313b7af2fce46139c04d9469cb72a.tar.gz depot-32f4cb5cbba313b7af2fce46139c04d9469cb72a.tar.bz2 depot-32f4cb5cbba313b7af2fce46139c04d9469cb72a.zip | |
25-jan sprint
Diffstat (limited to 'mod')
| -rw-r--r-- | mod/code/cses/.envrc | 1 | ||||
| -rw-r--r-- | mod/code/cses/default.nix | 13 | ||||
| -rw-r--r-- | mod/code/cses/problems/1068.cpp | 17 | ||||
| -rw-r--r-- | mod/code/cses/problems/1069.cpp | 23 | ||||
| -rw-r--r-- | mod/code/cses/problems/1070.cpp | 15 | ||||
| -rw-r--r-- | mod/code/cses/problems/1083.cpp | 20 | ||||
| -rw-r--r-- | mod/code/cses/problems/1094.cpp | 27 | ||||
| -rw-r--r-- | mod/tools/perf-flamegraph.nix | 12 | ||||
| -rw-r--r-- | mod/tools/typst/default.nix | 2 |
9 files changed, 129 insertions, 1 deletions
diff --git a/mod/code/cses/.envrc b/mod/code/cses/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/mod/code/cses/.envrc @@ -0,0 +1 @@ +use nix diff --git a/mod/code/cses/default.nix b/mod/code/cses/default.nix new file mode 100644 index 0000000..6538eb8 --- /dev/null +++ b/mod/code/cses/default.nix @@ -0,0 +1,13 @@ +{ pkgs ? import <nixpkgs> { }, ... }: + +pkgs.mkShell { + packages = with pkgs; [ + clang-tools + (writeShellScriptBin "cpprun" '' + TEMP=".tmp.cpp" + g++ -std=c++20 -O3 ./problems/"$1.cpp" -o $TEMP + ./$TEMP + rm $TEMP + '') + ]; +} diff --git a/mod/code/cses/problems/1068.cpp b/mod/code/cses/problems/1068.cpp new file mode 100644 index 0000000..8d05936 --- /dev/null +++ b/mod/code/cses/problems/1068.cpp @@ -0,0 +1,17 @@ +#include <iostream> + +int main(int argc, char *argv[]) { + unsigned long long n; + std::cin >> n; + + while (n != 1) { + std::cout << n << " "; + + if (n % 2 == 0) + n /= 2; + else + n = (n * 3) + 1; + } + + std::cout << 1; +} diff --git a/mod/code/cses/problems/1069.cpp b/mod/code/cses/problems/1069.cpp new file mode 100644 index 0000000..232d2f7 --- /dev/null +++ b/mod/code/cses/problems/1069.cpp @@ -0,0 +1,23 @@ +#include <iostream> + +int main() { + std::string input; + std::cin >> input; + + auto max = 0; + auto curr = '-'; + auto count = 0; + + for (auto const ch : input) { + if (curr != ch) { + curr = ch; + count = 0; + } + + count += 1; + max = std::max(max, count); + } + + std::cout << max; + return 0; +} diff --git a/mod/code/cses/problems/1070.cpp b/mod/code/cses/problems/1070.cpp new file mode 100644 index 0000000..131a644 --- /dev/null +++ b/mod/code/cses/problems/1070.cpp @@ -0,0 +1,15 @@ +#include <iostream> + +int main() { + int n; + std::cin >> n; + + if (n == 1) + std::cout << 1; + else if (n < 4) + std::cout << "NO SOLUTION"; + else { + for (auto i = 2; i <= n; i += 2) std::cout << i << " "; + for (auto i = 1; i <= n; i += 2) std::cout << i << " "; + } +} diff --git a/mod/code/cses/problems/1083.cpp b/mod/code/cses/problems/1083.cpp new file mode 100644 index 0000000..a3cd253 --- /dev/null +++ b/mod/code/cses/problems/1083.cpp @@ -0,0 +1,20 @@ +#include <iostream> +#include <set> + +using ull = unsigned long long; + +int main(int argc, char *argv[]) { + ull n; + std::cin >> n; + + auto set = std::set<ull>{}; + + std::string numstr; + while (std::getline(std::cin, numstr, ' ')) set.insert(std::stoi(numstr)); + + for (auto i = 1; i <= n; i++) { + if (set.contains(i)) continue; + std::cout << i; + break; + } +} diff --git a/mod/code/cses/problems/1094.cpp b/mod/code/cses/problems/1094.cpp new file mode 100644 index 0000000..56f3886 --- /dev/null +++ b/mod/code/cses/problems/1094.cpp @@ -0,0 +1,27 @@ +#include <iostream> +#include <vector> + +using ull = unsigned long long; + +int main() { + ull n; + auto arr = std::vector<ull>{}; + + std::cin >> n; + + std::string type; + while (std::cin >> type) arr.push_back(std::stoi(type)); + + ull count = 0; + auto last = arr[0]; + + for (auto const num : arr) { + if (num > last) { + last = num; + continue; + } + count += last - num; + } + + std::cout << count; +} diff --git a/mod/tools/perf-flamegraph.nix b/mod/tools/perf-flamegraph.nix new file mode 100644 index 0000000..b472b74 --- /dev/null +++ b/mod/tools/perf-flamegraph.nix @@ -0,0 +1,12 @@ +# Script that collects perf timing for the execution of a command and writes a +# flamegraph to stdout +{ pkgs, ... }: + +pkgs.writeShellScriptBin "perf-flamegraph" '' + set -euo pipefail + + ${pkgs.linuxPackages.perf}/bin/perf record -g --call-graph dwarf -F max "$@" + ${pkgs.linuxPackages.perf}/bin/perf script \ + | ${pkgs.flamegraph}/bin/stackcollapse-perf.pl \ + | ${pkgs.flamegraph}/bin/flamegraph.pl +'' diff --git a/mod/tools/typst/default.nix b/mod/tools/typst/default.nix index 3f81658..5f809d6 100644 --- a/mod/tools/typst/default.nix +++ b/mod/tools/typst/default.nix @@ -28,6 +28,6 @@ in depotPackages ]; - shellHook = "export XDG_DATA_HOME=${depotPackages}/share:$XDG_DATA_HOME"; + shellHook = "alias typst='export XDG_DATA_HOME=${depotPackages}/share:$XDG_DATA_HOME'"; }; } |
