1
0
forked from danmax/aoc

Added mememan's code and updated mine a bit

This commit is contained in:
2025-12-01 20:40:16 +00:00
parent 36a19996da
commit f1260bd73d
6 changed files with 1135 additions and 17 deletions

View File

@@ -0,0 +1,6 @@
[package]
name = "mememan"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@@ -0,0 +1,46 @@
use std::fs;
fn main() {
let start = std::time::Instant::now();
let raw = fs::read_to_string("../large.txt").unwrap();
let mut formatted: Vec<&str> = raw.split("\n").collect();
formatted.pop();
let mut point: i32 = 50;
let mut password_one = 0;
let mut password_two = 0;
for rot in formatted {
let mut chars = rot.chars();
let dir = chars.next().unwrap();
let dist = chars.as_str().parse::<i32>().unwrap();
if dir == 'L' {
if point - dist < 1 {
password_two += ((point - dist).abs() as f32 / 100.0).ceil() as i32;
point = (point - dist).rem_euclid(100);
if point == 0 {
password_one +=1;
}
// dbg!(point, ((point - dist).abs() as f32 / 100.0).ceil());
continue;
}
point = (point - dist).rem_euclid(100);
} else {
if point + dist > 99 {
password_two += ((point + dist) as f32 / 100.0).floor() as i32;
point = (point + dist).rem_euclid(100);
if point == 0 {
password_one += 1;
}
// dbg!(point, ((point + dist) as f32 / 100.0).floor());
continue;
}
point = (point + dist).rem_euclid(100);
}
if point == 0 {
password_one += 1;
password_two += 1;
}
// dbg!(point);
}
dbg!(password_one, password_two, std::time::Instant::now() - start);
}