From 68d6bff3ff78063a21bf815aae3eb5214680d988 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 1 Dec 2025 13:53:12 +0100 Subject: [PATCH 1/5] Remove `qt6.full` from the c++ devshell --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index 40dd6bf..b8ec797 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,6 @@ packages = with pkgs; [ gdb clang-tools - qt6.full ]; }; From 47023fc3dd71e1c834d0e4e2a7194839207c8000 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 1 Dec 2025 13:57:15 +0100 Subject: [PATCH 2/5] Update flake inputs --- flake.lock | 14 +++++++------- flake.nix | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index a4ac182..b86cd41 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1759439645, - "narHash": "sha256-oiAyQaRilPk525Z5aTtTNWNzSrcdJ7IXM0/PL3CGlbI=", + "lastModified": 1764522689, + "narHash": "sha256-SqUuBFjhl/kpDiVaKLQBoD8TLD+/cTUzzgVFoaHrkqY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "879bd460b3d3e8571354ce172128fbcbac1ed633", + "rev": "8bb5646e0bed5dbd3ab08c7a7cc15b75ab4e1d0f", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-25.05", + "ref": "nixos-25.11", "repo": "nixpkgs", "type": "github" } @@ -29,11 +29,11 @@ ] }, "locked": { - "lastModified": 1759544920, - "narHash": "sha256-yQwP0JOHi3Icq09GG5ufGuGrq2zIijglVFj3kkF2MHA=", + "lastModified": 1764557621, + "narHash": "sha256-kX5PoY8hQZ80+amMQgOO9t8Tc1JZ70gYRnzaVD4AA+o=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "bd3a63bbff2c4cb3cd48e9d49f54c2ccad457f70", + "rev": "93316876c2229460a5d6f5f052766cc4cef538ce", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index b8ec797..27280c3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; rust-overlay = { url = "github:oxalica/rust-overlay"; From d14d435b0a249208128b252ca297463cfd025293 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 1 Dec 2025 14:50:26 +0100 Subject: [PATCH 3/5] Solve 2025 day 1 part 1 in rust --- 2025/inputs/01.txt | 10 ++++++++ 2025/rust/.envrc | 1 + 2025/rust/day-01/Cargo.lock | 7 ++++++ 2025/rust/day-01/Cargo.toml | 6 +++++ 2025/rust/day-01/src/main.rs | 45 ++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 2025/inputs/01.txt create mode 100644 2025/rust/.envrc create mode 100644 2025/rust/day-01/Cargo.lock create mode 100644 2025/rust/day-01/Cargo.toml create mode 100644 2025/rust/day-01/src/main.rs diff --git a/2025/inputs/01.txt b/2025/inputs/01.txt new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/2025/inputs/01.txt @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/2025/rust/.envrc b/2025/rust/.envrc new file mode 100644 index 0000000..4196168 --- /dev/null +++ b/2025/rust/.envrc @@ -0,0 +1 @@ +use flake .#rust diff --git a/2025/rust/day-01/Cargo.lock b/2025/rust/day-01/Cargo.lock new file mode 100644 index 0000000..6e11d14 --- /dev/null +++ b/2025/rust/day-01/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-01" +version = "0.1.0" diff --git a/2025/rust/day-01/Cargo.toml b/2025/rust/day-01/Cargo.toml new file mode 100644 index 0000000..c43f1c8 --- /dev/null +++ b/2025/rust/day-01/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day-01" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/2025/rust/day-01/src/main.rs b/2025/rust/day-01/src/main.rs new file mode 100644 index 0000000..6f15cf3 --- /dev/null +++ b/2025/rust/day-01/src/main.rs @@ -0,0 +1,45 @@ +use std::fs::{self}; + +fn main() { + let rotations = read_input(); + + println!("Password: {}", count_neutral_positions(rotations)); +} + +fn read_input() -> Vec { + let contents = fs::read_to_string("../../inputs/01.txt").unwrap(); + let lines = contents.lines(); + + let mut rotations = vec![]; + + for line in lines { + let (direction, distance) = line.split_at(1); + + let distance = distance.parse::().unwrap(); + + let rotation = match direction { + "L" => distance * -1, + "R" => distance, + _ => panic!(), + }; + + rotations.push(rotation); + } + + rotations +} + +fn count_neutral_positions(rotations: Vec) -> i32 { + let mut counter = 0; + let mut position = 50; + + for rotation in rotations { + position = (position + rotation) % 100; + + if position == 0 { + counter += 1; + } + } + + counter +} From e2af8dddbe2260abbdd5406dce0a900af267b49d Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 1 Dec 2025 15:43:14 +0100 Subject: [PATCH 4/5] Solve 2025 day 1 part 2 in rust --- 2025/rust/day-01/src/main.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/2025/rust/day-01/src/main.rs b/2025/rust/day-01/src/main.rs index 6f15cf3..ca04183 100644 --- a/2025/rust/day-01/src/main.rs +++ b/2025/rust/day-01/src/main.rs @@ -1,12 +1,13 @@ use std::fs::{self}; fn main() { - let rotations = read_input(); + let rotations = read_rotations(); - println!("Password: {}", count_neutral_positions(rotations)); + println!("Password1: {}", count_zero_positions(&rotations)); + println!("Password2: {}", count_zero_clicks(&rotations)); } -fn read_input() -> Vec { +fn read_rotations() -> Vec { let contents = fs::read_to_string("../../inputs/01.txt").unwrap(); let lines = contents.lines(); @@ -18,7 +19,7 @@ fn read_input() -> Vec { let distance = distance.parse::().unwrap(); let rotation = match direction { - "L" => distance * -1, + "L" => -distance, "R" => distance, _ => panic!(), }; @@ -29,12 +30,12 @@ fn read_input() -> Vec { rotations } -fn count_neutral_positions(rotations: Vec) -> i32 { +fn count_zero_positions(rotations: &Vec) -> i32 { let mut counter = 0; let mut position = 50; for rotation in rotations { - position = (position + rotation) % 100; + position = (position + rotation).rem_euclid(100); if position == 0 { counter += 1; @@ -43,3 +44,24 @@ fn count_neutral_positions(rotations: Vec) -> i32 { counter } + +fn count_zero_clicks(rotations: &Vec) -> i32 { + let mut counter = 0; + let mut position = 50; + + for rotation in rotations { + position += rotation; + + counter += (position / 100).abs(); + if position < 0 && position != *rotation { + counter += 1; + } + if position == 0 { + counter += 1; + } + + position = position.rem_euclid(100); + } + + counter +} From 99554bc83b76852836e9acf6d51fd2e3fbcb258a Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 1 Dec 2025 16:16:28 +0100 Subject: [PATCH 5/5] Improve 2025 day 1 in rust --- 2025/rust/day-01/src/main.rs | 49 ++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/2025/rust/day-01/src/main.rs b/2025/rust/day-01/src/main.rs index ca04183..d8a8346 100644 --- a/2025/rust/day-01/src/main.rs +++ b/2025/rust/day-01/src/main.rs @@ -1,5 +1,8 @@ use std::fs::{self}; +const STARTING_POSITION: i32 = 50; +const DIAL_RANGE: i32 = 100; + fn main() { let rotations = read_rotations(); @@ -8,34 +11,26 @@ fn main() { } fn read_rotations() -> Vec { - let contents = fs::read_to_string("../../inputs/01.txt").unwrap(); - let lines = contents.lines(); - - let mut rotations = vec![]; - - for line in lines { - let (direction, distance) = line.split_at(1); - - let distance = distance.parse::().unwrap(); - - let rotation = match direction { - "L" => -distance, - "R" => distance, - _ => panic!(), - }; - - rotations.push(rotation); - } - - rotations + fs::read_to_string("../../inputs/01.txt") + .unwrap() + .lines() + .map(|line| { + let distance = line[1..].parse::().unwrap(); + if line.starts_with('L') { + -distance + } else { + distance + } + }) + .collect() } -fn count_zero_positions(rotations: &Vec) -> i32 { +fn count_zero_positions(rotations: &[i32]) -> i32 { let mut counter = 0; - let mut position = 50; + let mut position = STARTING_POSITION; for rotation in rotations { - position = (position + rotation).rem_euclid(100); + position = (position + rotation).rem_euclid(DIAL_RANGE); if position == 0 { counter += 1; @@ -45,14 +40,14 @@ fn count_zero_positions(rotations: &Vec) -> i32 { counter } -fn count_zero_clicks(rotations: &Vec) -> i32 { +fn count_zero_clicks(rotations: &[i32]) -> i32 { let mut counter = 0; - let mut position = 50; + let mut position = STARTING_POSITION; for rotation in rotations { position += rotation; - counter += (position / 100).abs(); + counter += (position / DIAL_RANGE).abs(); if position < 0 && position != *rotation { counter += 1; } @@ -60,7 +55,7 @@ fn count_zero_clicks(rotations: &Vec) -> i32 { counter += 1; } - position = position.rem_euclid(100); + position = position.rem_euclid(DIAL_RANGE); } counter