mirror of
https://github.com/SebastianStork/advent-of-code.git
synced 2026-01-21 21:31:33 +01:00
Compare commits
No commits in common. "3c4e0e431713f3e10cf2bc57f8100c782fa71c1d" and "99554bc83b76852836e9acf6d51fd2e3fbcb258a" have entirely different histories.
3c4e0e4317
...
99554bc83b
6 changed files with 19 additions and 71 deletions
1
.envrc
1
.envrc
|
|
@ -1 +0,0 @@
|
||||||
use flake
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,4 +3,3 @@
|
||||||
.idea/
|
.idea/
|
||||||
.direnv/
|
.direnv/
|
||||||
**/target
|
**/target
|
||||||
inputs
|
|
||||||
10
2025/inputs/01.txt
Normal file
10
2025/inputs/01.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
|
|
@ -4,14 +4,15 @@ const STARTING_POSITION: i32 = 50;
|
||||||
const DIAL_RANGE: i32 = 100;
|
const DIAL_RANGE: i32 = 100;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rotations = parse_rotations(&fs::read_to_string("../../inputs/01.txt").unwrap());
|
let rotations = read_rotations();
|
||||||
|
|
||||||
println!("Password1: {}", count_zero_positions(&rotations));
|
println!("Password1: {}", count_zero_positions(&rotations));
|
||||||
println!("Password2: {}", count_zero_clicks(&rotations));
|
println!("Password2: {}", count_zero_clicks(&rotations));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_rotations(contents: &str) -> Vec<i32> {
|
fn read_rotations() -> Vec<i32> {
|
||||||
contents
|
fs::read_to_string("../../inputs/01.txt")
|
||||||
|
.unwrap()
|
||||||
.lines()
|
.lines()
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
let distance = line[1..].parse::<i32>().unwrap();
|
let distance = line[1..].parse::<i32>().unwrap();
|
||||||
|
|
@ -59,29 +60,3 @@ fn count_zero_clicks(rotations: &[i32]) -> i32 {
|
||||||
|
|
||||||
counter
|
counter
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
const TEST_INPUT: &str = "L68
|
|
||||||
L30
|
|
||||||
R48
|
|
||||||
L5
|
|
||||||
R60
|
|
||||||
L55
|
|
||||||
L1
|
|
||||||
L99
|
|
||||||
R14
|
|
||||||
L82";
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_part1() {
|
|
||||||
assert_eq!(count_zero_positions(&parse_rotations(TEST_INPUT)), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_part2() {
|
|
||||||
assert_eq!(count_zero_clicks(&parse_rotations(TEST_INPUT)), 6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
18
flake.lock
generated
18
flake.lock
generated
|
|
@ -1,22 +1,5 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"inputs": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1764611941,
|
|
||||||
"narHash": "sha256-GEVJK9tSeNnGgYYRbjtYE/su75nxRvOm8h0Sf5GD70A=",
|
|
||||||
"ref": "refs/heads/main",
|
|
||||||
"rev": "5390449be22f56739e0840e35e46d54b1166886c",
|
|
||||||
"shallow": true,
|
|
||||||
"type": "git",
|
|
||||||
"url": "ssh://git@github.com/SebastianStork/advent-of-code-inputs.git"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"shallow": true,
|
|
||||||
"type": "git",
|
|
||||||
"url": "ssh://git@github.com/SebastianStork/advent-of-code-inputs.git"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1764522689,
|
"lastModified": 1764522689,
|
||||||
|
|
@ -35,7 +18,6 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"inputs": "inputs",
|
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
flake.nix
27
flake.nix
|
|
@ -6,42 +6,25 @@
|
||||||
url = "github:oxalica/rust-overlay";
|
url = "github:oxalica/rust-overlay";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
inputs = {
|
|
||||||
url = "git+ssh://git@github.com/SebastianStork/advent-of-code-inputs.git?shallow=1";
|
|
||||||
flake = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{
|
{ nixpkgs, rust-overlay, ... }:
|
||||||
nixpkgs,
|
|
||||||
rust-overlay,
|
|
||||||
inputs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
devShells.${system} = {
|
devShells.${system} = {
|
||||||
default = pkgs.mkShellNoCC {
|
|
||||||
packages = [ pkgs.stow ];
|
|
||||||
shellHook = ''
|
|
||||||
stow --dir=${inputs} --target=./. package
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
cpp = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
|
cpp = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
|
||||||
packages = [
|
packages = with pkgs; [
|
||||||
pkgs.gdb
|
gdb
|
||||||
pkgs.clang-tools
|
clang-tools
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
go = pkgs.mkShellNoCC {
|
go = pkgs.mkShellNoCC {
|
||||||
packages = [ pkgs.go ];
|
packages = with pkgs; [ go ];
|
||||||
};
|
};
|
||||||
|
|
||||||
rust =
|
rust =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue