forked from danmax/aoc
Added mememan's code and updated mine a bit
This commit is contained in:
6
2025/1/mememan/Cargo.toml
Normal file
6
2025/1/mememan/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "mememan"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
46
2025/1/mememan/src/main.rs
Normal file
46
2025/1/mememan/src/main.rs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user