mirror of
https://github.com/SebastianStork/advent-of-code.git
synced 2026-01-21 14:31:34 +01:00
Compare commits
No commits in common. "99554bc83b76852836e9acf6d51fd2e3fbcb258a" and "0099ac0585f906cfb1d94bf4aa81675c320ab459" have entirely different histories.
99554bc83b
...
0099ac0585
7 changed files with 9 additions and 94 deletions
|
|
@ -1,10 +0,0 @@
|
|||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
|
|
@ -1 +0,0 @@
|
|||
use flake .#rust
|
||||
7
2025/rust/day-01/Cargo.lock
generated
7
2025/rust/day-01/Cargo.lock
generated
|
|
@ -1,7 +0,0 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "day-01"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "day-01"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
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": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1764522689,
|
||||
"narHash": "sha256-SqUuBFjhl/kpDiVaKLQBoD8TLD+/cTUzzgVFoaHrkqY=",
|
||||
"lastModified": 1759439645,
|
||||
"narHash": "sha256-oiAyQaRilPk525Z5aTtTNWNzSrcdJ7IXM0/PL3CGlbI=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8bb5646e0bed5dbd3ab08c7a7cc15b75ab4e1d0f",
|
||||
"rev": "879bd460b3d3e8571354ce172128fbcbac1ed633",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-25.11",
|
||||
"ref": "nixos-25.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
|
@ -29,11 +29,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1764557621,
|
||||
"narHash": "sha256-kX5PoY8hQZ80+amMQgOO9t8Tc1JZ70gYRnzaVD4AA+o=",
|
||||
"lastModified": 1759544920,
|
||||
"narHash": "sha256-yQwP0JOHi3Icq09GG5ufGuGrq2zIijglVFj3kkF2MHA=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "93316876c2229460a5d6f5f052766cc4cef538ce",
|
||||
"rev": "bd3a63bbff2c4cb3cd48e9d49f54c2ccad457f70",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
|
||||
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
packages = with pkgs; [
|
||||
gdb
|
||||
clang-tools
|
||||
qt6.full
|
||||
];
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue