mirror of
https://github.com/SebastianStork/advent-of-code.git
synced 2026-01-21 16:51:34 +01:00
Compare commits
5 commits
0099ac0585
...
99554bc83b
| Author | SHA1 | Date | |
|---|---|---|---|
| 99554bc83b | |||
| e2af8dddbe | |||
| d14d435b0a | |||
| 47023fc3dd | |||
| 68d6bff3ff |
7 changed files with 94 additions and 9 deletions
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
|
||||||
1
2025/rust/.envrc
Normal file
1
2025/rust/.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake .#rust
|
||||||
7
2025/rust/day-01/Cargo.lock
generated
Normal file
7
2025/rust/day-01/Cargo.lock
generated
Normal file
|
|
@ -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"
|
||||||
6
2025/rust/day-01/Cargo.toml
Normal file
6
2025/rust/day-01/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "day-01"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
62
2025/rust/day-01/src/main.rs
Normal file
62
2025/rust/day-01/src/main.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
use std::fs::{self};
|
||||||
|
|
||||||
|
const STARTING_POSITION: i32 = 50;
|
||||||
|
const DIAL_RANGE: i32 = 100;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let rotations = read_rotations();
|
||||||
|
|
||||||
|
println!("Password1: {}", count_zero_positions(&rotations));
|
||||||
|
println!("Password2: {}", count_zero_clicks(&rotations));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_rotations() -> Vec<i32> {
|
||||||
|
fs::read_to_string("../../inputs/01.txt")
|
||||||
|
.unwrap()
|
||||||
|
.lines()
|
||||||
|
.map(|line| {
|
||||||
|
let distance = line[1..].parse::<i32>().unwrap();
|
||||||
|
if line.starts_with('L') {
|
||||||
|
-distance
|
||||||
|
} else {
|
||||||
|
distance
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn count_zero_positions(rotations: &[i32]) -> i32 {
|
||||||
|
let mut counter = 0;
|
||||||
|
let mut position = STARTING_POSITION;
|
||||||
|
|
||||||
|
for rotation in rotations {
|
||||||
|
position = (position + rotation).rem_euclid(DIAL_RANGE);
|
||||||
|
|
||||||
|
if position == 0 {
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
counter
|
||||||
|
}
|
||||||
|
|
||||||
|
fn count_zero_clicks(rotations: &[i32]) -> i32 {
|
||||||
|
let mut counter = 0;
|
||||||
|
let mut position = STARTING_POSITION;
|
||||||
|
|
||||||
|
for rotation in rotations {
|
||||||
|
position += rotation;
|
||||||
|
|
||||||
|
counter += (position / DIAL_RANGE).abs();
|
||||||
|
if position < 0 && position != *rotation {
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
if position == 0 {
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
position = position.rem_euclid(DIAL_RANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
counter
|
||||||
|
}
|
||||||
14
flake.lock
generated
14
flake.lock
generated
|
|
@ -2,16 +2,16 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1759439645,
|
"lastModified": 1764522689,
|
||||||
"narHash": "sha256-oiAyQaRilPk525Z5aTtTNWNzSrcdJ7IXM0/PL3CGlbI=",
|
"narHash": "sha256-SqUuBFjhl/kpDiVaKLQBoD8TLD+/cTUzzgVFoaHrkqY=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "879bd460b3d3e8571354ce172128fbcbac1ed633",
|
"rev": "8bb5646e0bed5dbd3ab08c7a7cc15b75ab4e1d0f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-25.05",
|
"ref": "nixos-25.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
@ -29,11 +29,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1759544920,
|
"lastModified": 1764557621,
|
||||||
"narHash": "sha256-yQwP0JOHi3Icq09GG5ufGuGrq2zIijglVFj3kkF2MHA=",
|
"narHash": "sha256-kX5PoY8hQZ80+amMQgOO9t8Tc1JZ70gYRnzaVD4AA+o=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "bd3a63bbff2c4cb3cd48e9d49f54c2ccad457f70",
|
"rev": "93316876c2229460a5d6f5f052766cc4cef538ce",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
||||||
|
|
||||||
rust-overlay = {
|
rust-overlay = {
|
||||||
url = "github:oxalica/rust-overlay";
|
url = "github:oxalica/rust-overlay";
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
gdb
|
gdb
|
||||||
clang-tools
|
clang-tools
|
||||||
qt6.full
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue