forked from danmax/aoc
Added mememan's code and updated mine a bit
This commit is contained in:
1043
2025/1/deadvey/Cargo.lock
generated
1043
2025/1/deadvey/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -2,3 +2,7 @@
|
||||
name = "deadvey"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
|
||||
trash_parallelism = "0.1.102"
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::time::Instant;
|
||||
|
||||
// Right = up/increase
|
||||
// Left = down/decrease
|
||||
fn main() -> io::Result<()>
|
||||
#[tokio::main]
|
||||
async fn main()
|
||||
{
|
||||
let start = Instant::now();
|
||||
let file_contents: String = fs::read_to_string("large.txt")?;
|
||||
let lines: Vec<&str> = file_contents
|
||||
.split("\n")
|
||||
.collect();
|
||||
|
||||
let mut position: i32 = 50;
|
||||
let mut total1: i32 = 0;
|
||||
let mut total2: i32 = 0;
|
||||
|
||||
println!("The dial starts by pointing at {position}");
|
||||
let start = Instant::now();
|
||||
let file_contents: String = fs::read_to_string("../large.txt").unwrap();
|
||||
//let file_contents = read_file_to_string_async("large.txt").await.unwrap();
|
||||
let file_read = start.elapsed();
|
||||
let mut lines: Vec<&str> = file_contents
|
||||
.split("\n")
|
||||
.collect();
|
||||
lines.pop();
|
||||
let preamble = start.elapsed();
|
||||
|
||||
for index in 0..&lines.len()-1
|
||||
for line in lines
|
||||
{
|
||||
let movement = &lines[index][0..1];
|
||||
let mut number: i32 = lines[index][1..lines[index].len()].parse().unwrap();
|
||||
let movement = line.chars().next().unwrap();
|
||||
let mut number: i32 = line[1..line.len()].parse().unwrap();
|
||||
|
||||
if movement == "L" {
|
||||
if movement == 'L' {
|
||||
number = -number
|
||||
};
|
||||
if number < 0 {
|
||||
@@ -41,8 +43,17 @@ fn main() -> io::Result<()>
|
||||
let end = start.elapsed();
|
||||
println!("part1: {total1}");
|
||||
println!("part2: {total2}");
|
||||
println!("Took: {:.2?}",end);
|
||||
|
||||
|
||||
Ok(())
|
||||
println!("Times:
|
||||
File read: {:.2?}
|
||||
Preamble: {:.2?}
|
||||
Loop: {:.2?}
|
||||
Average Loop: {:.2?}
|
||||
Total: {:.2?}
|
||||
",
|
||||
file_read,
|
||||
preamble,
|
||||
end-preamble,
|
||||
(end-preamble)/(100000).try_into().unwrap(),
|
||||
end);
|
||||
}
|
||||
|
||||
|
||||
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