47 lines
1.5 KiB
Rust
47 lines
1.5 KiB
Rust
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);
|
|
}
|