From 1414ea66b298e056762b80914f360f4c4a27cceb Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Wed, 4 Dec 2024 21:55:45 -0500 Subject: [PATCH] chore: move jj up a level --- .envrc | 1 - .gitignore => 2024/.gitignore | 0 {day_1 => 2024/day_1}/.gitignore | 0 {day_1 => 2024/day_1}/Cargo.lock | 0 {day_1 => 2024/day_1}/Cargo.toml | 0 {day_1 => 2024/day_1}/input.txt | 0 {day_1 => 2024/day_1}/src/main.rs | 0 {day_3 => 2024/day_3}/.gitignore | 0 {day_3 => 2024/day_3}/Cargo.lock | 0 {day_3 => 2024/day_3}/Cargo.toml | 0 {day_3 => 2024/day_3}/input.txt | 0 {day_3 => 2024/day_3}/src/main.rs | 0 {day_4 => 2024/day_4}/.gitignore | 0 {day_4 => 2024/day_4}/Cargo.lock | 0 {day_4 => 2024/day_4}/Cargo.toml | 0 {day_4 => 2024/day_4}/input.txt | 0 {day_4 => 2024/day_4}/src/main.rs | 0 2024/day_5/.gitignore | 1 + 2024/day_5/Cargo.lock | 7 + 2024/day_5/Cargo.toml | 6 + 2024/day_5/input.txt | 1366 +++++++++++++++++++++++++++++ 2024/day_5/src/main.rs | 166 ++++ 2024/day_5/text_input.txt | 28 + 2024/day_6/.gitignore | 1 + 2024/day_6/Cargo.lock | 7 + 2024/day_6/Cargo.toml | 6 + 2024/day_6/input.txt | 130 +++ 2024/day_6/src/main.rs | 166 ++++ 2024/day_6/test_input.txt | 10 + flake.lock => 2024/flake.lock | 0 flake.nix => 2024/flake.nix | 0 2025/nilla.nix | 45 + 2025/npins/default.nix | 247 ++++++ 2025/npins/sources.json | 44 + 34 files changed, 2230 insertions(+), 1 deletion(-) delete mode 100644 .envrc rename .gitignore => 2024/.gitignore (100%) rename {day_1 => 2024/day_1}/.gitignore (100%) rename {day_1 => 2024/day_1}/Cargo.lock (100%) rename {day_1 => 2024/day_1}/Cargo.toml (100%) rename {day_1 => 2024/day_1}/input.txt (100%) rename {day_1 => 2024/day_1}/src/main.rs (100%) rename {day_3 => 2024/day_3}/.gitignore (100%) rename {day_3 => 2024/day_3}/Cargo.lock (100%) rename {day_3 => 2024/day_3}/Cargo.toml (100%) rename {day_3 => 2024/day_3}/input.txt (100%) rename {day_3 => 2024/day_3}/src/main.rs (100%) rename {day_4 => 2024/day_4}/.gitignore (100%) rename {day_4 => 2024/day_4}/Cargo.lock (100%) rename {day_4 => 2024/day_4}/Cargo.toml (100%) rename {day_4 => 2024/day_4}/input.txt (100%) rename {day_4 => 2024/day_4}/src/main.rs (100%) create mode 100644 2024/day_5/.gitignore create mode 100644 2024/day_5/Cargo.lock create mode 100644 2024/day_5/Cargo.toml create mode 100644 2024/day_5/input.txt create mode 100644 2024/day_5/src/main.rs create mode 100644 2024/day_5/text_input.txt create mode 100644 2024/day_6/.gitignore create mode 100644 2024/day_6/Cargo.lock create mode 100644 2024/day_6/Cargo.toml create mode 100644 2024/day_6/input.txt create mode 100644 2024/day_6/src/main.rs create mode 100644 2024/day_6/test_input.txt rename flake.lock => 2024/flake.lock (100%) rename flake.nix => 2024/flake.nix (100%) create mode 100644 2025/nilla.nix create mode 100644 2025/npins/default.nix create mode 100644 2025/npins/sources.json diff --git a/.envrc b/.envrc deleted file mode 100644 index 443b0ee..0000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use_flake . \ No newline at end of file diff --git a/.gitignore b/2024/.gitignore similarity index 100% rename from .gitignore rename to 2024/.gitignore diff --git a/day_1/.gitignore b/2024/day_1/.gitignore similarity index 100% rename from day_1/.gitignore rename to 2024/day_1/.gitignore diff --git a/day_1/Cargo.lock b/2024/day_1/Cargo.lock similarity index 100% rename from day_1/Cargo.lock rename to 2024/day_1/Cargo.lock diff --git a/day_1/Cargo.toml b/2024/day_1/Cargo.toml similarity index 100% rename from day_1/Cargo.toml rename to 2024/day_1/Cargo.toml diff --git a/day_1/input.txt b/2024/day_1/input.txt similarity index 100% rename from day_1/input.txt rename to 2024/day_1/input.txt diff --git a/day_1/src/main.rs b/2024/day_1/src/main.rs similarity index 100% rename from day_1/src/main.rs rename to 2024/day_1/src/main.rs diff --git a/day_3/.gitignore b/2024/day_3/.gitignore similarity index 100% rename from day_3/.gitignore rename to 2024/day_3/.gitignore diff --git a/day_3/Cargo.lock b/2024/day_3/Cargo.lock similarity index 100% rename from day_3/Cargo.lock rename to 2024/day_3/Cargo.lock diff --git a/day_3/Cargo.toml b/2024/day_3/Cargo.toml similarity index 100% rename from day_3/Cargo.toml rename to 2024/day_3/Cargo.toml diff --git a/day_3/input.txt b/2024/day_3/input.txt similarity index 100% rename from day_3/input.txt rename to 2024/day_3/input.txt diff --git a/day_3/src/main.rs b/2024/day_3/src/main.rs similarity index 100% rename from day_3/src/main.rs rename to 2024/day_3/src/main.rs diff --git a/day_4/.gitignore b/2024/day_4/.gitignore similarity index 100% rename from day_4/.gitignore rename to 2024/day_4/.gitignore diff --git a/day_4/Cargo.lock b/2024/day_4/Cargo.lock similarity index 100% rename from day_4/Cargo.lock rename to 2024/day_4/Cargo.lock diff --git a/day_4/Cargo.toml b/2024/day_4/Cargo.toml similarity index 100% rename from day_4/Cargo.toml rename to 2024/day_4/Cargo.toml diff --git a/day_4/input.txt b/2024/day_4/input.txt similarity index 100% rename from day_4/input.txt rename to 2024/day_4/input.txt diff --git a/day_4/src/main.rs b/2024/day_4/src/main.rs similarity index 100% rename from day_4/src/main.rs rename to 2024/day_4/src/main.rs diff --git a/2024/day_5/.gitignore b/2024/day_5/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/2024/day_5/.gitignore @@ -0,0 +1 @@ +/target diff --git a/2024/day_5/Cargo.lock b/2024/day_5/Cargo.lock new file mode 100644 index 0000000..f1e2e15 --- /dev/null +++ b/2024/day_5/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day_5" +version = "0.1.0" diff --git a/2024/day_5/Cargo.toml b/2024/day_5/Cargo.toml new file mode 100644 index 0000000..0736fe2 --- /dev/null +++ b/2024/day_5/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day_5" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/2024/day_5/input.txt b/2024/day_5/input.txt new file mode 100644 index 0000000..c0a9534 --- /dev/null +++ b/2024/day_5/input.txt @@ -0,0 +1,1366 @@ +48|39 +39|84 +39|23 +95|51 +95|76 +95|61 +14|52 +14|49 +14|39 +14|53 +85|19 +85|25 +85|61 +85|35 +85|58 +74|86 +74|55 +74|49 +74|18 +74|83 +74|47 +45|49 +45|76 +45|86 +45|22 +45|35 +45|18 +45|37 +52|58 +52|16 +52|23 +52|12 +52|31 +52|27 +52|46 +52|15 +49|71 +49|44 +49|54 +49|91 +49|58 +49|25 +49|52 +49|84 +49|46 +86|26 +86|95 +86|52 +86|51 +86|48 +86|91 +86|55 +86|22 +86|11 +86|37 +69|18 +69|86 +69|98 +69|34 +69|79 +69|95 +69|22 +69|27 +69|15 +69|65 +69|37 +66|83 +66|65 +66|18 +66|92 +66|48 +66|32 +66|16 +66|47 +66|22 +66|95 +66|37 +66|49 +15|22 +15|83 +15|37 +15|49 +15|65 +15|85 +15|31 +15|95 +15|79 +15|47 +15|74 +15|16 +15|86 +71|16 +71|66 +71|92 +71|84 +71|15 +71|54 +71|25 +71|53 +71|31 +71|98 +71|46 +71|69 +71|74 +71|58 +79|49 +79|34 +79|86 +79|26 +79|18 +79|14 +79|22 +79|91 +79|77 +79|48 +79|37 +79|52 +79|95 +79|35 +79|74 +76|39 +76|84 +76|94 +76|77 +76|12 +76|24 +76|46 +76|69 +76|15 +76|53 +76|23 +76|19 +76|52 +76|11 +76|66 +76|25 +19|94 +19|79 +19|71 +19|92 +19|66 +19|16 +19|53 +19|45 +19|69 +19|31 +19|24 +19|25 +19|12 +19|54 +19|84 +19|58 +19|98 +11|25 +11|27 +11|84 +11|12 +11|24 +11|66 +11|19 +11|51 +11|69 +11|16 +11|53 +11|94 +11|58 +11|44 +11|23 +11|39 +11|35 +11|52 +92|37 +92|91 +92|31 +92|48 +92|76 +92|14 +92|34 +92|55 +92|32 +92|85 +92|86 +92|98 +92|83 +92|49 +92|18 +92|26 +92|95 +92|11 +92|74 +23|16 +23|18 +23|86 +23|74 +23|92 +23|66 +23|79 +23|55 +23|45 +23|47 +23|26 +23|37 +23|15 +23|24 +23|12 +23|98 +23|34 +23|48 +23|65 +23|27 +37|51 +37|61 +37|26 +37|47 +37|49 +37|84 +37|52 +37|34 +37|55 +37|39 +37|14 +37|19 +37|77 +37|35 +37|58 +37|91 +37|83 +37|76 +37|85 +37|11 +37|32 +55|44 +55|19 +55|52 +55|39 +55|84 +55|54 +55|32 +55|47 +55|71 +55|51 +55|83 +55|35 +55|91 +55|85 +55|76 +55|11 +55|58 +55|61 +55|53 +55|49 +55|25 +55|77 +27|48 +27|18 +27|65 +27|34 +27|74 +27|37 +27|47 +27|98 +27|55 +27|83 +27|79 +27|16 +27|86 +27|85 +27|45 +27|66 +27|22 +27|49 +27|15 +27|26 +27|14 +27|92 +27|95 +51|16 +51|84 +51|54 +51|77 +51|27 +51|94 +51|66 +51|23 +51|19 +51|25 +51|71 +51|65 +51|15 +51|52 +51|39 +51|44 +51|46 +51|24 +51|12 +51|31 +51|92 +51|69 +51|58 +51|53 +83|32 +83|52 +83|35 +83|76 +83|94 +83|44 +83|84 +83|14 +83|71 +83|77 +83|61 +83|12 +83|85 +83|23 +83|39 +83|51 +83|19 +83|54 +83|25 +83|49 +83|11 +83|53 +83|58 +83|91 +94|66 +94|15 +94|74 +94|12 +94|55 +94|86 +94|16 +94|69 +94|26 +94|45 +94|34 +94|65 +94|98 +94|18 +94|23 +94|48 +94|46 +94|92 +94|37 +94|31 +94|22 +94|27 +94|24 +94|79 +54|15 +54|26 +54|92 +54|46 +54|69 +54|22 +54|23 +54|66 +54|24 +54|74 +54|31 +54|37 +54|16 +54|48 +54|34 +54|94 +54|65 +54|79 +54|45 +54|18 +54|12 +54|27 +54|86 +54|98 +58|23 +58|31 +58|48 +58|25 +58|79 +58|65 +58|15 +58|24 +58|16 +58|54 +58|86 +58|22 +58|94 +58|46 +58|27 +58|12 +58|45 +58|69 +58|92 +58|74 +58|66 +58|44 +58|98 +58|18 +61|65 +61|46 +61|54 +61|19 +61|77 +61|52 +61|39 +61|25 +61|66 +61|12 +61|24 +61|94 +61|44 +61|51 +61|27 +61|15 +61|69 +61|71 +61|23 +61|84 +61|58 +61|92 +61|16 +61|53 +77|53 +77|84 +77|24 +77|58 +77|65 +77|12 +77|31 +77|92 +77|46 +77|23 +77|66 +77|27 +77|25 +77|39 +77|19 +77|71 +77|16 +77|45 +77|52 +77|94 +77|69 +77|44 +77|54 +77|15 +32|35 +32|61 +32|51 +32|71 +32|91 +32|53 +32|46 +32|39 +32|52 +32|11 +32|23 +32|77 +32|76 +32|12 +32|27 +32|54 +32|94 +32|19 +32|58 +32|44 +32|25 +32|24 +32|69 +32|84 +31|85 +31|79 +31|35 +31|91 +31|86 +31|18 +31|76 +31|98 +31|55 +31|45 +31|95 +31|11 +31|49 +31|22 +31|14 +31|74 +31|34 +31|32 +31|26 +31|48 +31|83 +31|61 +31|37 +31|47 +34|26 +34|77 +34|85 +34|47 +34|61 +34|52 +34|19 +34|11 +34|58 +34|91 +34|35 +34|95 +34|39 +34|25 +34|14 +34|53 +34|71 +34|84 +34|76 +34|51 +34|83 +34|55 +34|49 +34|32 +46|22 +46|26 +46|98 +46|27 +46|45 +46|15 +46|83 +46|86 +46|24 +46|18 +46|65 +46|79 +46|34 +46|16 +46|55 +46|74 +46|95 +46|66 +46|92 +46|37 +46|47 +46|48 +46|69 +46|31 +26|53 +26|95 +26|35 +26|47 +26|19 +26|76 +26|83 +26|55 +26|11 +26|51 +26|77 +26|52 +26|39 +26|71 +26|91 +26|44 +26|32 +26|84 +26|85 +26|14 +26|49 +26|61 +26|25 +26|58 +91|24 +91|23 +91|94 +91|69 +91|46 +91|27 +91|76 +91|58 +91|53 +91|11 +91|19 +91|39 +91|52 +91|61 +91|84 +91|51 +91|25 +91|54 +91|77 +91|35 +91|44 +91|12 +91|15 +91|71 +53|48 +53|69 +53|44 +53|94 +53|92 +53|66 +53|79 +53|98 +53|31 +53|27 +53|45 +53|15 +53|16 +53|22 +53|12 +53|86 +53|54 +53|24 +53|58 +53|23 +53|74 +53|46 +53|65 +53|25 +12|74 +12|16 +12|65 +12|66 +12|95 +12|31 +12|34 +12|37 +12|47 +12|24 +12|98 +12|92 +12|15 +12|22 +12|69 +12|86 +12|27 +12|46 +12|55 +12|26 +12|45 +12|18 +12|79 +12|48 +24|34 +24|15 +24|26 +24|27 +24|95 +24|55 +24|37 +24|14 +24|74 +24|48 +24|31 +24|66 +24|45 +24|98 +24|18 +24|86 +24|92 +24|16 +24|65 +24|47 +24|83 +24|79 +24|22 +24|85 +84|54 +84|98 +84|53 +84|46 +84|58 +84|23 +84|22 +84|12 +84|16 +84|94 +84|45 +84|66 +84|65 +84|31 +84|86 +84|79 +84|25 +84|24 +84|69 +84|15 +84|74 +84|27 +84|92 +84|44 +18|53 +18|35 +18|55 +18|77 +18|85 +18|37 +18|83 +18|26 +18|52 +18|14 +18|39 +18|51 +18|19 +18|71 +18|11 +18|84 +18|91 +18|49 +18|32 +18|34 +18|76 +18|95 +18|61 +18|47 +25|65 +25|12 +25|94 +25|37 +25|45 +25|24 +25|92 +25|66 +25|79 +25|74 +25|22 +25|86 +25|98 +25|18 +25|44 +25|48 +25|23 +25|27 +25|16 +25|69 +25|31 +25|46 +25|54 +25|15 +98|83 +98|11 +98|22 +98|49 +98|37 +98|61 +98|85 +98|79 +98|95 +98|32 +98|35 +98|34 +98|48 +98|76 +98|77 +98|91 +98|47 +98|74 +98|86 +98|26 +98|51 +98|14 +98|18 +98|55 +22|76 +22|61 +22|47 +22|35 +22|85 +22|77 +22|51 +22|95 +22|26 +22|14 +22|37 +22|71 +22|83 +22|32 +22|55 +22|39 +22|52 +22|49 +22|91 +22|19 +22|18 +22|34 +22|11 +22|48 +47|95 +47|11 +47|14 +47|51 +47|49 +47|54 +47|39 +47|94 +47|85 +47|44 +47|61 +47|71 +47|58 +47|83 +47|19 +47|32 +47|77 +47|25 +47|84 +47|53 +47|76 +47|52 +47|35 +47|91 +35|54 +35|27 +35|77 +35|84 +35|71 +35|46 +35|12 +35|16 +35|51 +35|39 +35|52 +35|61 +35|15 +35|92 +35|94 +35|53 +35|66 +35|58 +35|44 +35|19 +35|25 +35|24 +35|23 +35|69 +65|45 +65|86 +65|95 +65|83 +65|31 +65|11 +65|35 +65|34 +65|18 +65|74 +65|32 +65|91 +65|26 +65|22 +65|49 +65|37 +65|14 +65|79 +65|55 +65|85 +65|76 +65|47 +65|98 +65|48 +44|74 +44|16 +44|86 +44|27 +44|48 +44|24 +44|94 +44|15 +44|65 +44|69 +44|66 +44|12 +44|22 +44|34 +44|23 +44|79 +44|92 +44|98 +44|31 +44|37 +44|18 +44|54 +44|45 +44|46 +16|18 +16|55 +16|92 +16|22 +16|79 +16|98 +16|26 +16|74 +16|45 +16|86 +16|76 +16|31 +16|47 +16|32 +16|83 +16|91 +16|48 +16|49 +16|85 +16|34 +16|65 +16|14 +16|95 +16|37 +48|71 +48|61 +48|52 +48|95 +48|76 +48|37 +48|91 +48|51 +48|77 +48|84 +48|34 +48|49 +48|18 +48|83 +48|11 +48|47 +48|26 +48|35 +48|32 +48|55 +48|14 +48|85 +48|19 +39|15 +39|65 +39|79 +39|19 +39|69 +39|53 +39|44 +39|31 +39|45 +39|54 +39|46 +39|92 +39|98 +39|16 +39|24 +39|58 +39|94 +39|25 +39|71 +39|66 +39|12 +39|27 +95|58 +95|11 +95|39 +95|44 +95|19 +95|94 +95|35 +95|83 +95|71 +95|91 +95|54 +95|77 +95|53 +95|52 +95|14 +95|84 +95|49 +95|85 +95|32 +95|23 +95|25 +14|35 +14|76 +14|94 +14|25 +14|46 +14|58 +14|84 +14|23 +14|11 +14|71 +14|12 +14|77 +14|32 +14|19 +14|61 +14|44 +14|54 +14|85 +14|91 +14|51 +85|53 +85|49 +85|76 +85|71 +85|44 +85|94 +85|11 +85|12 +85|39 +85|91 +85|77 +85|52 +85|54 +85|69 +85|46 +85|23 +85|51 +85|84 +85|32 +74|61 +74|95 +74|26 +74|91 +74|48 +74|14 +74|37 +74|52 +74|34 +74|39 +74|32 +74|77 +74|22 +74|51 +74|76 +74|35 +74|11 +74|85 +45|83 +45|91 +45|11 +45|51 +45|79 +45|34 +45|47 +45|98 +45|55 +45|14 +45|74 +45|48 +45|26 +45|61 +45|32 +45|85 +45|95 +52|19 +52|98 +52|54 +52|71 +52|45 +52|25 +52|65 +52|92 +52|53 +52|66 +52|39 +52|84 +52|94 +52|69 +52|24 +52|44 +49|23 +49|11 +49|39 +49|51 +49|53 +49|35 +49|61 +49|24 +49|19 +49|94 +49|12 +49|77 +49|32 +49|69 +49|76 +86|49 +86|14 +86|83 +86|32 +86|76 +86|85 +86|61 +86|77 +86|18 +86|19 +86|34 +86|35 +86|47 +86|39 +69|92 +69|16 +69|83 +69|66 +69|48 +69|24 +69|26 +69|47 +69|14 +69|45 +69|55 +69|74 +69|31 +66|26 +66|79 +66|91 +66|31 +66|34 +66|85 +66|45 +66|98 +66|86 +66|14 +66|55 +66|74 +15|45 +15|14 +15|26 +15|32 +15|18 +15|98 +15|48 +15|34 +15|66 +15|92 +15|55 +71|45 +71|24 +71|44 +71|86 +71|12 +71|79 +71|23 +71|65 +71|94 +71|27 +79|85 +79|55 +79|11 +79|83 +79|61 +79|51 +79|76 +79|47 +79|32 +76|51 +76|27 +76|44 +76|35 +76|54 +76|58 +76|61 +76|71 +19|65 +19|23 +19|46 +19|15 +19|27 +19|74 +19|44 +11|61 +11|15 +11|77 +11|71 +11|54 +11|46 +92|47 +92|22 +92|79 +92|45 +92|65 +23|46 +23|22 +23|69 +23|31 +37|95 +37|53 +37|71 +55|95 +55|14 +27|31 + +61,58,51,32,12,14,71 +58,25,54,14,12,94,32,76,39 +35,53,26,77,14,71,25,76,85,55,51,49,95 +32,91,76,11,35,61,51,77,52,19,71,84,53,58,25,44,54,94,23,12,46,69,24 +18,37,26,47,83,85,49,32,76,35,61,77,52,19,71 +39,19,84,53,58,25,54,12,69,66,31 +61,52,71,84,44,66,92 +71,84,44,46,45 +32,91,76,35,51,77,52,71,84,53,58,25,44,54,94,23,12 +48,18,37,34,26,55,47,95,83,49,32,91,11,35,61,77,52,39,71 +25,54,12,46,79,74,18 +94,65,44,39,46,66,52,15,54,71,84,92,12,77,23,27,31,16,25,58,19,69,53 +19,71,53,25,44,54,94,23,46,69,24,15,66,16,65,31,79 +49,76,11,35,77,52,39,71,54,23,12,46,69 +69,58,19,71,35,61,16,46,54 +54,16,35,94,25,15,51 +34,26,55,47,95,14,85,49,32,91,76,11,35,61,51,77,52,39,19,71,84,53,58 +76,54,77,24,46,12,27,35,53,52,61,39,58,69,94,71,91,23,51 +14,27,83,85,37,65,16,18,79,22,48,66,86,92,47 +19,52,61,58,44,84,51 +27,15,66,16,92,31,98,79,74,86,18,37,26,55,85 +94,46,27,66,65,45,98,74,86,48,18,37,34 +66,46,53,52,77,35,16,27,61 +18,37,34,55,47,95,83,14,85,49,32,91,76,11,35,61,51,77,39,71,84 +61,51,77,52,39,19,71,84,53,58,25,54,94,23,12,46,69,24,27,15,66,16,92 +98,74,86,22,48,18,37,34,26,55,47,95,83,14,85,49,32,91,76,11,51 +49,32,51,39,84,53,69 +46,15,66,65,45,98,86,48,18,34,55,47,95 +25,94,23,12,66,16,92,31,79,86,22,48,18 +32,91,76,51,77,52,39,19,53,58,25,54,94,23,12,69,24 +34,26,55,47,83,14,76,35,61,51,77,39,19,84,53 +34,18,95,74,35,37,47,52,76,32,22,48,51,86,77,85,11,55,83,14,26 +25,44,54,23,46,69,27,16,92,31,45,98,22,48,18 +91,58,11,76,26,49,19,95,14,61,39 +48,18,37,34,55,47,95,14,85,49,32,91,76,35,61,51,77,52,39,19,71 +31,66,27,79,23,86,22,92,15,44,54,94,16,37,12,18,45 +16,24,66,53,12,77,19,65,15,51,27,94,23,52,39,46,58,69,92,84,71,54,25 +44,54,94,12,46,24,27,15,92,31,86,22,37 +39,71,53,54,15,45,98 +69,53,44,54,77,58,27,39,61,25,12,94,23,51,35,84,71,15,46,66,16,19,52 +94,46,69,31,66,84,86,58,98,16,24 +55,47,95,49,76,51,19,71,84,58,44 +12,46,69,16,92,65,31,45,98,79,74,86,22,48,18,37,34,26,47 +52,11,77,58,27,35,39,24,44,19,46,23,54,53,71,76,12 +71,66,94,15,84,46,61,52,11,19,53,23,51,69,27,54,58,12,39,44,24 +79,86,22,18,37,47,83,14,91,76,51 +79,48,47,95,11 +12,24,46,34,66,74,86,98,69,37,45,92,26,55,47,18,65,22,16 +71,65,54,15,39,69,98,23,46,58,94,24,45 +79,74,86,83,14 +35,19,84,69,27 +54,46,66,31,98,48,18,37,34 +18,65,34,14,55,66,24 +94,46,27,65,98,22,26 +66,69,45,46,79,23,86,92,58,94,84,53,24,31,44,54,16,12,65,27,98 +27,66,92,65,31,98,86,18,26,55,95,83,85 +86,34,79,83,66,55,22,16,32 +85,49,32,76,11,77,52,39,84,53,25,54,94,12,46 +74,47,31,22,92,18,79,37,48,14,16,85,98,83,34,45,65,95,66,27,86 +86,22,18,37,34,26,47,95,83,85,49,32,11,35,61,77,39 +79,55,95,49,91 +54,94,23,12,46,69,24,27,15,66,16,65,31,45,98,79,74,86,22,48,18,37,34 +27,53,58,92,69,79,94 +83,14,85,49,32,91,76,11,35,61,51,77,52,39,19,71,84,53,58,44,54,94,23 +23,12,46,69,24,27,15,66,16,92,65,31,98,79,74,86,22,48,18,37,34,26,55 +53,54,19,85,46,91,84,71,44,52,23,51,77,76,39,32,25,94,49,11,61 +32,35,55,22,74 +35,61,51,77,39,19,71,84,53,58,25,44,54,94,23,12,46,69,24,27,15,66,16 +95,74,11,49,85,83,45,34,32,61,37,35,14,55,18,79,26,22,98,86,91,47,48 +66,31,45,98,22,48,47,95,83,14,85 +61,51,77,52,39,19,71,84,53,58,25,54,94,23,12,46,69,27,15,16,92 +85,49,91,35,61,77,52,39,19,71,84,53,58,25,94,12,46 +47,26,79,65,34,37,74,83,98,22,45,55,18,16,66,69,15,86,95 +61,51,46,23,12,25,85,58,52,39,54,19,76,91,94,32,35 +48,37,95,85,32,91,76,51,71 +84,58,25,44,54,94,23,12,46,69,24,27,15,66,16,92,65,31,98,79,86 +77,54,14,35,49,84,76,51,11,44,94,95,52,71,19 +69,24,27,15,66,16,92,65,31,45,98,79,74,22,48,18,37,34,26,55,47,95,83 +61,71,53,44,46,24,66 +66,16,45,18,55,47,83,85,32 +69,24,27,66,98,79,86,22,48,18,37,34,26,55,47,95,83 +85,19,71,84,44,11,53,47,77,49,76,54,14,91,25 +11,83,61,77,51,35,58,94,95 +49,32,91,76,11,35,61,51,77,52,39,19,84,58,25,44,94,23,12,46,69 +25,44,54,94,23,12,24,27,15,66,16,92,65,31,79,74,86,22,18 +71,49,48,95,76,83,34,47,37 +14,49,32,91,61,77,52,19,84,58,44 +45,44,79,53,16,23,15,58,92,31,66,22,98,74,25,24,46,69,65,86,54,27,94 +11,61,52,53,58,94,66 +77,84,54,69,71,76,24,23,94,11,44,27,91,12,61,53,35,19,39,46,25 +92,65,31,45,74,86,48,18,37,34,26,55,47,95,83,14,85,91,76 +46,24,15,66,16,92,98,79,86,18,34,26,55 +11,35,61,51,77,52,39,19,71,53,58,25,44,54,94,23,12,69,24,15,66 +49,76,39,53,58 +71,84,53,58,25,44,54,94,23,12,69,24,27,15,66,16,92,65,31,45,98,79,74 +14,25,47,32,54,19,85,95,58 +53,12,25,19,15,54,52,31,44,39,69 +32,91,76,35,61,51,77,52,39,19,84,58,25,44,54,94,23,12,46,69,24 +55,83,91,49,86,22,76,37,32,14,39,47,34 +94,23,12,46,69,24,27,66,16,92,65,31,45,98,79,74,86,22,48,18,37,34,26 +55,83,49,32,35,39,19 +19,16,92,46,31,69,44,52,39,12,71,45,53,15,84,66,58 +71,84,35,53,58,11,91,61,51,83,25,14,47,77,32,76,44,55,95,52,19,49,39 +24,27,65,31,45,98,22,48,18,34,26,55,47,95,14 +46,23,58,31,98,12,92,24,45,54,71,94,19,16,53,25,39,44,69 +92,65,98,18,47,83,14,85,76 +26,32,34,83,49,91,52,85,47,11,51,76,74,35,48 +65,45,98,79,74,22,48,18,55,47,95,83,14,85,49,32,91,76,11 +47,39,26,22,49,34,76 +77,52,84,54,23,46,27,16,31 +15,66,16,92,65,31,98,74,86,48,18,37,34,55,47 +92,55,48,18,27,45,65,24,66,83,69 +22,18,37,95,85,49,32,35,61,77,19 +49,91,77,71,58,25,54,94,69 +39,51,85,77,49,19,61,18,22,37,14,34,11 +47,85,32,91,76,52,39,19,71,84,53,44,54 +76,35,61,52,39,71,53,58,25,94,12,46,24,27,15 +61,51,84,25,46,35,76,32,52,12,23,69,19,94,58,11,39,53,24,54,77,44,91 +31,45,66,49,79,95,26,98,65,48,14,55,22,74,92 +92,46,48,26,66 +25,44,94,12,65,31,79,22,18 +45,98,79,55,14,34,26,83,74,15,86,92,85,49,18,66,65,16,22 +25,32,53,58,94,23,19,54,71,11,39,77,52,84,69,76,49 +52,39,84,53,25,44,12,24,15,66,16,92,65,31,45 +52,39,19,58,44,54,94,23,12,69,24,15,66,16,92,31,45 +95,66,47,26,18,83,32,45,85,98,86,37,55 +31,45,86,48,37,26,95,83,14,85,32,76,35 +94,24,92,58,19,54,69,16,84,53,27,51,77,12,15,61,39,25,52,23,71,66,44 +44,54,94,23,12,46,69,24,66,92,31,98,79 +66,16,92,65,45,98,79,74,86,22,48,18,37,26,55,47,95,83,14,49,32 +98,18,47,14,85,49,51 +55,85,91,11,84 +32,91,11,35,51,77,52,39,19,84,58,54,94,23,69 +83,84,11,26,77,34,14,85,71,52,18 +32,49,91,76,83,94,71,19,23,61,58 +44,69,16,98,65,58,12,84,94,25,79,27,31,54,46,24,86,66,74,45,92 +65,94,15,12,45,74,23,58,16,84,86,31,69,24,98,92,66 +61,51,77,52,19,71,84,53,25,44,94,23,12,46,69,24,27,15,66 +79,34,55,61,98,45,47,74,83,49,76,11,32 +86,22,48,18,37,83,85,32,91,76,11,35,61,51,77,52,39 +65,45,86,55,95,85,32,76,11 +15,66,16,92,31,45,98,79,74,86,22,48,18,37,34,26,95,83,14,85,49 +54,58,53,16,71,15,98,69,94,65,46,31,66,25,92,84,44,24,19,23,27 +26,61,37,14,71,51,19,76,91 +15,92,79,74,86,22,48,26,55,83,14,85,49 +26,74,83,76,49,31,47,35,37,95,86 +71,83,95,34,19,39,14,51,85,49,52,61,32,48,55 +69,15,66,92,79,74,37,34,55,47,95 +47,51,19,39,35,85,84,91,26,71,49,55,25,11,52 +26,14,76,32,37,95,86,35,55,79,83,11,91,47,34,22,31,98,85,45,48 +35,53,19,32,91,46,12,25,11,61,54,51,71 +98,79,74,86,22,18,37,34,26,55,47,95,83,85,49,32,91,11,51 +79,22,34,47,32,11,77 +31,69,45,95,83,16,55,65,98,22,26,37,74 +74,86,22,37,34,26,55,95,85,32,91,76,11,77,52 +39,19,71,53,25,44,54,46,69,24,27,66,16,65,31,45,98 +47,51,11,77,58,85,52 +45,48,37,83,49,32,91 +85,26,77,95,19,18,51,34,55,52,91,32,11,84,39 +79,45,18,94,48,74,16,12,92,98,37,26,27,23,69,46,34,86,31 +48,34,14,45,86,98,18,85,47,22,55,76,79,32,31,91,35,83,37 +76,77,52,71,44 +26,55,47,95,83,14,85,49,32,91,76,11,35,61,51,77,52,39,19,71,84,58,25 +45,98,79,86,48,18,34,26,47,95,85,91,61 +24,44,19,71,15,12,27,51,52,92,84 +69,24,27,65,98,22,48,18,55,47,83 +61,34,11,74,91,51,48,55,52,86,37,85,14,49,95,76,22 +71,46,27,15,66,92,79 +58,46,16,31,27,54,53,66,12,23,71,52,84,25,44,94,77 +61,77,39,19,71,84,25,44,54,94,24,27,15,66,16 +51,52,15,12,24,66,54,35,46,16,69,84,53 +74,86,22,48,18,34,26,55,47,95,83,14,85,49,32,91,76,11,35,61,51,77,52 +34,26,47,14,32,76,35,39,71 +37,26,47,83,85,49,76,11,35,61,51,77,53 +66,24,98,86,15 +91,76,35,61,51,52,39,19,53,58,54,94,23,46,27 +16,92,45,74,86,22,18,37,34,26,55,85,49,32,91 +12,74,58,79,23,31,22,25,86 +98,79,22,48,18,14,85,49,32,76,11,61,51 +34,26,55,47,95,83,14,85,49,32,91,76,11,35,61,51,52,39,19,71,84,53,58 +51,52,39,58,25,44,54,12,46,69,24,66,16,92,65 +24,44,58,12,46,92,22,79,86,74,54,65,23 +86,22,18,26,95,32,91,76,51 +71,54,69,24,15,66,16,31,45,98,74 +15,92,65,31,45,98,79,74,86,22,48,18,34,26,55,95,14,85,49 +53,44,54,94,23,12,46,69,24,27,15,66,92,98,74,86,22 +16,92,65,31,45,98,22,18,37,34,55,95,83,14,32 +34,47,95,83,14,85,49,91,76,11,35,51,77,52,19,71,84,53,58 +55,45,76,37,35,83,31 diff --git a/2024/day_5/src/main.rs b/2024/day_5/src/main.rs new file mode 100644 index 0000000..c71ab8d --- /dev/null +++ b/2024/day_5/src/main.rs @@ -0,0 +1,166 @@ +#![feature(test)] + +extern crate test; + +use std::fs; + +#[derive(Debug)] +enum Input { + Rule(String, String), + Update(String), + None +} + +impl Input { + fn is_rule(&self) -> bool { + match *self { + Input::Rule(_, _) => true, + _ => false + } + } + + fn is_none(&self) -> bool { + match *self { + Input::None => true, + _ => false + } + } +} + +fn part_1(input: &Vec) { + let rules = input.iter().filter(|i| i.is_rule()).collect::>(); + + let mut sum: usize = 0; + + for item in input { + match item { + Input::Update(update) => { + let mut c = true; + for rule in rules.clone() { + match rule { + Input::Rule(before, after) => { + if update.find(before).is_some() && update.find(after).is_some() { + let i_b = update.find(before).unwrap(); + let i_a = update.find(after).unwrap(); + + if i_b > i_a { + c = false; + } + } + }, + _ => () + } + }; + + if c { + let sp = update.split(',').collect::>(); + sum += sp[sp.len() / 2].parse::().unwrap(); + } + }, + _ => () + } + } + + println!("Part 1: {sum}") + +} + +fn part_2(input: &Vec) { + let rules = input.iter().filter(|i| i.is_rule()).collect::>(); + + let mut sum: usize = 0; + + for item in input { + match item { + Input::Update(update) => { + let mut updated = update.split(',').collect::>(); + let mut c = true; + for _ in 0..2 { + for rule in rules.clone() { + match rule { + Input::Rule(before, after) => { + if update.find(before).is_some() && update.find(after).is_some() { + let b_idx = updated.iter().position(|i| *i == before).unwrap_or(usize::MAX); + let a_idx = updated.iter().position(|i| *i == after).unwrap_or(usize::MAX); + + if b_idx > a_idx { + updated = [&updated[0..a_idx], [updated[b_idx]].as_slice(), &updated[a_idx..b_idx], &updated[b_idx+1..]].concat().to_vec(); + c = false; + } + } + }, + _ => () + } + }; + } + + if !c { + sum += updated[updated.len() / 2].parse::().unwrap(); + } + }, + _ => () + } + } + + println!("Part 2: {sum}") +} + +fn parse_input(input: &str) -> Option> { + Some(input.lines().map(|line| { + if line.find('|').is_some() { + let mut s = line.split('|'); + Input::Rule(s.next().unwrap().to_string(), s.next().unwrap().to_string()) + } else { + if !line.is_empty() { + Input::Update(line.to_string()) + } else { + Input::None + } + } + }).filter(|i| !i.is_none()).collect()) +} + +fn main() { + let file = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + part_1(&input); + part_2(&input); +} + +#[test] +fn test_main() { + let file = fs::read_to_string("./text_input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + part_1(&input); + part_2(&input); +} + +#[bench] +fn full(b: &mut test::Bencher) { + b.iter(|| main()); +} + +#[bench] +fn input_only(b: &mut test::Bencher) { + let input = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + b.iter(|| parse_input(input.as_str())); +} + +#[bench] +fn part_one(b: &mut test::Bencher) { + let file = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + b.iter(|| part_1(&input)); +} + +#[bench] +fn part_two(b: &mut test::Bencher) { + let file = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + b.iter(|| part_2(&input)); +} diff --git a/2024/day_5/text_input.txt b/2024/day_5/text_input.txt new file mode 100644 index 0000000..9d146d6 --- /dev/null +++ b/2024/day_5/text_input.txt @@ -0,0 +1,28 @@ +47|53 +97|13 +97|61 +97|47 +75|29 +61|13 +75|53 +29|13 +97|29 +53|29 +61|53 +97|53 +61|29 +47|13 +75|47 +97|75 +47|61 +75|61 +47|29 +75|13 +53|13 + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 +75,97,47,61,53 +61,13,29 +97,13,75,29,47 diff --git a/2024/day_6/.gitignore b/2024/day_6/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/2024/day_6/.gitignore @@ -0,0 +1 @@ +/target diff --git a/2024/day_6/Cargo.lock b/2024/day_6/Cargo.lock new file mode 100644 index 0000000..150f3f7 --- /dev/null +++ b/2024/day_6/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day_6" +version = "0.1.0" diff --git a/2024/day_6/Cargo.toml b/2024/day_6/Cargo.toml new file mode 100644 index 0000000..bf6482e --- /dev/null +++ b/2024/day_6/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day_6" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/2024/day_6/input.txt b/2024/day_6/input.txt new file mode 100644 index 0000000..40d9596 --- /dev/null +++ b/2024/day_6/input.txt @@ -0,0 +1,130 @@ +........#.............................................#.........#..............#.......#....................#....................# +......................#........#........................#.............##............................#.#.............#..........#.. +....#..................................#..................#.........#....#..............#..#......................#........#...#.. +.....#...#...............#................#..........................#......#.....................#.......................#....... +......................................................##.#....#..................................................................# +#....#....................#..................................#.....................................#......................#....... +.......#...........................#.......................#......#...#.................................................#...#..... +....................##..........................#................#..........................#.#..................#....#.........#. +#..................................#...............#...............#.........................#............##...................... +.............................#....................................#...............#.........#..........#.......................#.. +.................................#............###.......#............##......#...............................#...............#.#.. +.#..........................................#.......#.......................##..#........#........#...............#............... +......#...#............#.#..............#...................#..........................................................##......... +#................##....................................................................#........#.................#...#........... +...#..........#..........................##......#....#..............................#......................................#..... +..............................##.#..........................................................#..............................#...... +......#...........#....#..................#............#....................................................................#..... +.....................#........................#.......................................................#........................... +...................#.#..........................................................................................#.#............... +.........................................##.........................................................#.......#...###......#........ +...............................................................##.......................#..........................#.............. +...#...........#.................#..............#......#.....#..........................#....................#....#............... +.................................#................#................#..............................................#.......##.....# +........#..........................#................#.......................#...................#................................. +.............................#.............................#..........#.........................#........#........................ +....#................#.#................#...........................................................#...#....#......#......#...... +........#..............................#...............................#.................#........................................ +...........................................#..#........#...#...........#..#.............#......................................... +.#.................#.#................................#................#.#..................................#........#............ +.......#..........................................#.................................................................#............. +...................#....................................................#..#...............................................#...... +...#.#........#...#.....#.....................................................................................................#... +......#.........................#......................#.............#.....................#...................................... +..........................#............#.................................#..#..........#........#......................#.......... +...#..#......#.......................#........................#................................................................... +............#...........#................#..............#......................................................................... +.#........#....#.........................................#........................................#............................... +...#......................##.........#.......#.#...........#................................................#...#................. +...........#......#.........#....#.....#.......................................................#.............#.................... +.............#...#..............................................#.........#.....##....................#...#.........#............. +...............#................................#..........................................#.....#.#.........................#...# +................#.....#..#.............#..............#..............#.......#.................................................... +......#.........................................................................................................#.........##...... +..#...........................#.#...........................................#..#.....#............................................ +...#...#..................#..................................#.........#...................#..................................#... +............#..#.....................#.........................................#.......#..................................#....... +...#.......................................................................#.............................#........................ +......#..................#....................................#......##........................................................... +.#...............#.....#..........................................................................................#............... +...#.............#.........................#.....................#...#..........#....#............................#............... +...#............................#.......#...........#.........#........#.....#...........#...................................#.... +.....................#...................#................................#...............................#......#.........#..##.. +.............#........................................................................................#........................##. +.....#.......#.......#............................................................................................................ +............................................#................................................................#..............#..... +....#..#......................................................#...................................................#............... +.................................#...##..................#.................................................#....#................. +........#...................................#...#..........................................................#...................... +........................#........##...........#.......#........#...................................#.............................. +...........#...#...................................................#..............#......#...............#.#..................#... +........#.............................................#........................................................................... +........#................#......#..........#..#........#.#.......#...#........................#..#......................#.......#. +.......#..........................................................................................................#.....#.....#... +......................##....................#.....#.................#...........#.......................#.##..........#......#.... +....................................##....................................................................#.................#..... +..#.................................#.#...........#............................................#....#............................. +#...................................#...........................................#............#.........#...............#.......... +.......................#.............................................................#..........#...#.............#.....#......... +#..................#.#.............................................................................#.................#............ +.....................#......#.......#...........#..........................................^...............................#...... +................................#......................#.#.....#..............#..................#....#.#......#....#............. +............................................................................#........#.....................................#...... +.............#......................................................#...................................#......##..#....#......... +...............#.................#...................#...............#............................................................ +..............#...........#..#...........................................#...................................#..........#......... +..........#...........................#...................#..............#...#.......#..........#...................#............. +.............#.#..................................#....#..#............#.....................#................#...#.....#......... +...................#..........................................................#............##..................................... +...........................................#............#........................................................................# +..#..............................#....#........................................................................................... +..#..#............#...........................#...#...........#............#.....#.................#.............................. +....#...................#.........#............................................................................................... +.......#..........................#....................................##........#.................##...#.#........#..#........... +.#........................#....#.......#.....#...................#.............................................#.................. +..#...............................................................#................................................#.............. +.....#........................................#................................................................................... +..........................................#..........................................................#............................ +....................###.........................#............................#...#...........#............#....................... +.....#.....#...............#........#.#....#...................#...........#........#...........#................................. +................................................................................................#...##............................ +......................#............#.........................#.......................#.....#...........#...#.#.................... +............................#....................#..................#..............#..................................#........... +...........................#...................................#..............................................................#... +..................#................#.....................#...................#........#..............#............................ +............#.............#.....................#..................#.........#......................#............#............#... +....#..........................#...............................................................................................#.. +................#.....................................#.............................#...........#........................#........ +#.##...........#.........................................#...............#..........................................#.#........... +........................................#..............#.....................#............#.....#................................. +.......#....##..#..#.....#........................................................................................................ +....##.............#..............................#............................................................................... +.....#........................#.........#..#......#........#......................#.......#..............#..........#.......#..... +..#....#.........................#.#....................#..#.......#.............#..................#........#..................#. +..........##....#........................................................................#........................................ +........#......#................................................................................................#................# +.....#.......#...#.............#....................................#..#........................#...#..............#....#......... +.............#...................................................##...#........................................................... +..............#.............................................#.............#................#.............#..............#......... +..#....#..........#.....#......#......................#................................#...............................#.......... +.................................................................................##......#...........................#.....#...... +..#....#..........#.......#.........................................#...............#..#............................#........#.... +...........#........#.#....................#........#.....................................#..................#.................... +.......#............#................#...........#.............#......#.........#...........................#..................... +#.#....#.#...............#....#.....#.......................#...............................#...................##...#............ +.................##...#.................................................................#...........................#............. +.....#........................................#.........#...................................................#..................... +....................#.....................#................................................#...##.....................#........... +...............#...............................................................#....#............................................. +.................#................#...#.....................................#......#....................#...............#.#....... +...................#............................................#..#....#..#........#...............................#.........#... +..#........#...............#..................#.....#..................#.....................................#........##...#...... +.....#.....#....#.....#................#.#.....................##.............................................................#... +................#............#......#......#.......................................................#....................#........# +........#..............#..#......................................................................##.....##........................ +.........#.............................#.........#.......................................#..........................#.##.......... +.#...................#........................................................#....#......................................#....... +....#..........#.....#.........................................................................................#.................. +.......#.............................#............#.........................#....#....#........#......#.....#.......#............. +..#.......#........................#........................#..................................................................... +........................#...............................#.#.............#................................#..................#..... diff --git a/2024/day_6/src/main.rs b/2024/day_6/src/main.rs new file mode 100644 index 0000000..8a75274 --- /dev/null +++ b/2024/day_6/src/main.rs @@ -0,0 +1,166 @@ +#![feature(test)] + +extern crate test; + +use std::fs; + +fn walk_guard(mut grid: Vec>) -> (Vec>, bool) { + println!("walking"); + let mut x: i32 = -1; + let y = grid.iter().position(|line| { + let t = line.iter().position(|c| *c == '<' || *c == '>' || *c == 'v' || *c == '^'); + if t.is_some() { + x = t.unwrap().try_into().unwrap(); + true + } else { + false + } + }); + + if y.is_none() { + return (grid, true) + } + + let real_x: usize = x.try_into().unwrap(); + let real_y: usize = y.unwrap(); + + match grid[real_y][real_x] { + '^' => { + if real_y.checked_sub(1).is_some() { + let ahead = grid[real_y-1][real_x]; + if ahead == '.' { + grid[real_y-1][real_x] = '^'; + grid[real_y][real_x] = 'X'; + } else { + grid[real_y][real_x] = '>'; + } + } else { + grid[real_y][real_x] = 'X'; + } + }, + '>' => { + if (real_x + 1) < grid[real_y].len() { + let ahead = grid[real_y][real_x+1]; + if ahead == '.' { + grid[real_y][real_x+1] = '>'; + grid[real_y][real_x] = 'X'; + } else { + grid[real_y][real_x] = 'v'; + } + } else { + grid[real_y][real_x] = 'X'; + } + }, + 'v' => { + if (real_y + 1) < grid.len() { + let ahead = grid[real_y+1][real_x]; + if ahead == '.' { + grid[real_y+1][real_x] = 'v'; + grid[real_y][real_x] = 'X'; + } else { + grid[real_y][real_x] = '<'; + } + } else { + grid[real_y][real_x] = 'X'; + } + }, + '<' => { + if real_x.checked_sub(1).is_some() { + let ahead = grid[real_y][real_x-1]; + if ahead == '.' { + grid[real_y][real_x-1] = '<'; + grid[real_y][real_x] = 'X'; + } else { + grid[real_y][real_x] = '^'; + } + } else { + grid[real_y][real_x] = 'X'; + } + }, + _ => {} + }; + (grid, false) +} + +fn part_1(input: &Vec>) { + let mut grid = input.to_vec(); + let mut c = false; + + while !c { + (grid, c) = walk_guard(grid); + for line in &grid { + println!("{:?}", line); + } + } + + let mut sum: usize = 0; + for line in grid { + for c in line { + if c == 'X' { + sum += 1; + } + } + } + + println!("Part 1: {sum}") +} + +fn part_2(input: &Vec>) { + +} + +fn parse_input(input: &str) -> Option>> { + Some( + input.lines().map( + |line| + line.chars().collect() + ).collect() + ) +} + +fn main() { + let file = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + part_1(&input); + part_2(&input); +} + +#[test] +fn test_main() { + let file = fs::read_to_string("./test_input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + + println!("{:?}", input); + part_1(&input); + part_2(&input); +} + +#[bench] +fn full(b: &mut test::Bencher) { + b.iter(|| main()); +} + +#[bench] +fn input_only(b: &mut test::Bencher) { + let input = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + b.iter(|| parse_input(input.as_str())); +} + +#[bench] +fn part_one(b: &mut test::Bencher) { + let file = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + b.iter(|| part_1(&input)); +} + +#[bench] +fn part_two(b: &mut test::Bencher) { + let file = fs::read_to_string("./input.txt").expect("Couldn't read file"); + + let input = parse_input(file.as_str()).unwrap(); + b.iter(|| part_2(&input)); +} diff --git a/2024/day_6/test_input.txt b/2024/day_6/test_input.txt new file mode 100644 index 0000000..a4eb402 --- /dev/null +++ b/2024/day_6/test_input.txt @@ -0,0 +1,10 @@ +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#... diff --git a/flake.lock b/2024/flake.lock similarity index 100% rename from flake.lock rename to 2024/flake.lock diff --git a/flake.nix b/2024/flake.nix similarity index 100% rename from flake.nix rename to 2024/flake.nix diff --git a/2025/nilla.nix b/2025/nilla.nix new file mode 100644 index 0000000..0ebf1ea --- /dev/null +++ b/2025/nilla.nix @@ -0,0 +1,45 @@ +let + pins = import ./npins; + + nilla = import pins.nilla; +in +nilla.create ({ config }: { + config = { + inputs = { + fenix = { + src = pins.fenix; + }; + + nixpkgs = { + src = pins.nixpkgs; + + settings = { + overlays = [ + config.inputs.fenix.result.overlays.default + ]; + }; + }; + }; + + shells.default = config.shells.rust; + shells.rust = { + systems = [ "x86_64-linux" ]; + + shell = { mkShell, fenix, bacon, pkg-config, ... }: + mkShell { + packages = [ + (fenix.complete.withComponents [ + "cargo" + "clippy" + "rust-src" + "rustc" + "rustfmt" + "rust-analyzer" + ]) + bacon + pkg-config + ]; + }; + }; + }; +}) diff --git a/2025/npins/default.nix b/2025/npins/default.nix new file mode 100644 index 0000000..b844b31 --- /dev/null +++ b/2025/npins/default.nix @@ -0,0 +1,247 @@ +/* + This file is provided under the MIT licence: + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +# Generated by npins. Do not modify; will be overwritten regularly +let + # Backwards-compatibly make something that previously didn't take any arguments take some + # The function must return an attrset, and will unfortunately be eagerly evaluated + # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments + mkFunctor = + fn: + let + e = builtins.tryEval (fn { }); + in + (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; }; + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = + first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatStrings = builtins.concatStringsSep ""; + + # If the environment variable NPINS_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + # (Taken from Niv for compatibility) + mayOverride = + name: path: + let + envVarName = "NPINS_OVERRIDE_${saneName}"; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv envVarName; + in + if ersatz == "" then + path + else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( + if builtins.substring 0 1 ersatz == "/" then + /. + ersatz + else + /. + builtins.getEnv "PWD" + "/${ersatz}" + ); + + mkSource = + name: spec: + { + pkgs ? null, + }: + assert spec ? type; + let + # Unify across builtin and pkgs fetchers. + # `fetchGit` requires a wrapper because of slight API differences. + fetchers = + if pkgs == null then + { + inherit (builtins) fetchTarball fetchurl; + # For some fucking reason, fetchGit has a different signature than the other builtin fetchers … + fetchGit = args: (builtins.fetchGit args).outPath; + } + else + { + fetchTarball = + { + url, + sha256, + }: + pkgs.fetchzip { + inherit url sha256; + extension = "tar"; + }; + inherit (pkgs) fetchurl; + fetchGit = + { + url, + submodules, + rev, + name, + narHash, + }: + pkgs.fetchgit { + inherit url rev name; + fetchSubmodules = submodules; + hash = narHash; + }; + }; + + # Dispatch to the correct code path based on the type + path = + if spec.type == "Git" then + mkGitSource fetchers spec + else if spec.type == "GitRelease" then + mkGitSource fetchers spec + else if spec.type == "PyPi" then + mkPyPiSource fetchers spec + else if spec.type == "Channel" then + mkChannelSource fetchers spec + else if spec.type == "Tarball" then + mkTarballSource fetchers spec + else if spec.type == "Container" then + mkContainerSource pkgs spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = mayOverride name path; }; + + mkGitSource = + { + fetchTarball, + fetchGit, + ... + }: + { + repository, + revision, + url ? null, + submodules, + hash, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null && !submodules then + fetchTarball { + inherit url; + sha256 = hash; + } + else + let + url = + if repository.type == "Git" then + repository.url + else if repository.type == "GitHub" then + "https://github.com/${repository.owner}/${repository.repo}.git" + else if repository.type == "GitLab" then + "${repository.server}/${repository.repo_path}.git" + else + throw "Unrecognized repository type ${repository.type}"; + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName url revision; + in + fetchGit { + rev = revision; + narHash = hash; + + inherit name submodules url; + }; + + mkPyPiSource = + { fetchurl, ... }: + { + url, + hash, + ... + }: + fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { fetchTarball, ... }: + { + url, + hash, + ... + }: + fetchTarball { + inherit url; + sha256 = hash; + }; + + mkTarballSource = + { fetchTarball, ... }: + { + url, + locked_url ? url, + hash, + ... + }: + fetchTarball { + url = locked_url; + sha256 = hash; + }; + + mkContainerSource = + pkgs: + { + image_name, + image_tag, + image_digest, + ... + }: + if pkgs == null then + builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers" + else + pkgs.dockerTools.pullImage { + imageName = image_name; + imageDigest = image_digest; + finalImageTag = image_tag; + }; +in +mkFunctor ( + { + input ? ./sources.json, + }: + let + data = + if builtins.isPath input then + # while `readFile` will throw an error anyways if the path doesn't exist, + # we still need to check beforehand because *our* error can be caught but not the one from the builtin + # *piegames sighs* + if builtins.pathExists input then + builtins.fromJSON (builtins.readFile input) + else + throw "Input path ${toString input} does not exist" + else if builtins.isAttrs input then + input + else + throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; + version = data.version; + in + if version == 7 then + builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins + else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" +) diff --git a/2025/npins/sources.json b/2025/npins/sources.json new file mode 100644 index 0000000..9a14cb4 --- /dev/null +++ b/2025/npins/sources.json @@ -0,0 +1,44 @@ +{ + "pins": { + "fenix": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "nix-community", + "repo": "fenix" + }, + "branch": "monthly", + "submodules": false, + "revision": "df3c2e78ec13418f85c1f26e77a50f865ec57d38", + "url": "https://github.com/nix-community/fenix/archive/df3c2e78ec13418f85c1f26e77a50f865ec57d38.tar.gz", + "hash": "sha256-+oo9W5rz03TjfpNqDSLEQwgKiuBbjrHdORyTHli2RuM=" + }, + "nilla": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "nilla-nix", + "repo": "nilla" + }, + "branch": "main", + "submodules": false, + "revision": "6d814dafa6f397ac2087333e5515c617faccba6f", + "url": "https://github.com/nilla-nix/nilla/archive/6d814dafa6f397ac2087333e5515c617faccba6f.tar.gz", + "hash": "sha256-A4zg3po1tyfh1if+LIllKtUGoWLFSwJSztvH2MG22qU=" + }, + "nixpkgs": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "nixos", + "repo": "nixpkgs" + }, + "branch": "nixos-unstable", + "submodules": false, + "revision": "2d293cbfa5a793b4c50d17c05ef9e385b90edf6c", + "url": "https://github.com/nixos/nixpkgs/archive/2d293cbfa5a793b4c50d17c05ef9e385b90edf6c.tar.gz", + "hash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=" + } + }, + "version": 7 +} -- 2.51.2