forked from danmax/aoc
Compare commits
10 Commits
1eb0384e35
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bad7dafe2b | |||
| 3e214636ca | |||
| 51926a19bf | |||
| ba2391bd8e | |||
| 5a0326faa4 | |||
| f1260bd73d | |||
| 36a19996da | |||
| e519a4d412 | |||
| 4eb1a406ae | |||
| 012bf6099d |
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
large.txt
|
||||
medium.txt
|
||||
small.txt
|
||||
|
||||
target
|
||||
debug
|
||||
*.swp
|
||||
Cargo.lock
|
||||
1050
2025/1/deadvey/Cargo.lock
generated
Normal file
1050
2025/1/deadvey/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
8
2025/1/deadvey/Cargo.toml
Normal file
8
2025/1/deadvey/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "deadvey"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
|
||||
trash_parallelism = "0.1.102"
|
||||
59
2025/1/deadvey/src/main.rs
Normal file
59
2025/1/deadvey/src/main.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use std::fs;
|
||||
use std::time::Instant;
|
||||
|
||||
// Right = up/increase
|
||||
// Left = down/decrease
|
||||
#[tokio::main]
|
||||
async fn main()
|
||||
{
|
||||
let mut position: i32 = 50;
|
||||
let mut total1: i32 = 0;
|
||||
let mut total2: i32 = 0;
|
||||
|
||||
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 line in lines
|
||||
{
|
||||
let movement = line.chars().next().unwrap();
|
||||
let mut number: i32 = line[1..line.len()].parse().unwrap();
|
||||
|
||||
if movement == 'L' {
|
||||
number = -number
|
||||
};
|
||||
if number < 0 {
|
||||
total2 += (100 - position - number) / 100 - (position == 0) as i32
|
||||
}
|
||||
else {
|
||||
total2 += (number+position) / 100
|
||||
};
|
||||
position = (position + number).rem_euclid(100);
|
||||
if position == 0 {
|
||||
total1 += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let end = start.elapsed();
|
||||
println!("part1: {total1}");
|
||||
println!("part2: {total2}");
|
||||
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);
|
||||
}
|
||||
6
2025/2/deadvey/Cargo.toml
Normal file
6
2025/2/deadvey/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "deadvey"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
73
2025/2/deadvey/src/main.rs
Normal file
73
2025/2/deadvey/src/main.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use std::fs;
|
||||
use std::time::Instant;
|
||||
|
||||
fn algorithm(vector: &Vec<Vec<&str>>) -> (u64, u64) {
|
||||
let mut total1: u64 = 0;
|
||||
let mut total2: u64 = 0;
|
||||
for pair in vector
|
||||
{
|
||||
let num_1: u64 = pair[0].parse().unwrap();
|
||||
let num_2: u64 = pair[1].parse().unwrap();
|
||||
for num in num_1..=num_2 { // Loop over each number in the range
|
||||
let num_string = num.to_string();
|
||||
let num_length = num_string.len();
|
||||
for chunk_width in (1..=(num_length/2)).rev() {
|
||||
if num_length % chunk_width == 0 {
|
||||
let chunks = num_length / chunk_width;
|
||||
let mut same: bool = true;
|
||||
let mut previous = &num_string[0..chunk_width];
|
||||
for i in 0..chunks {
|
||||
let current = &num_string[i*chunk_width..i*chunk_width+chunk_width];
|
||||
if current != previous {
|
||||
same = false;
|
||||
break;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
if same {
|
||||
total2 += num;
|
||||
if chunks == 2 {
|
||||
total1 += num;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(total1, total2)
|
||||
}
|
||||
|
||||
// you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice.
|
||||
// So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.
|
||||
fn main() {
|
||||
let start = Instant::now();
|
||||
|
||||
let mut file_contents: String = fs::read_to_string("../large.txt").unwrap();
|
||||
file_contents.pop();// Remove \n
|
||||
// Split it up
|
||||
let pairs: Vec<Vec<&str>> = file_contents
|
||||
.split(",")
|
||||
.collect::<Vec<&str>>()
|
||||
.iter()
|
||||
.map(|s| s.split('-').collect())
|
||||
.collect();
|
||||
let file_read = start.elapsed();
|
||||
|
||||
let (total1, total2) = algorithm(&pairs);
|
||||
|
||||
// There's a lot of converting between int and string
|
||||
let end = start.elapsed();
|
||||
println!("part1: {total1}");
|
||||
println!("part2: {total2}");
|
||||
println!("Times:
|
||||
File read: {:.2?}
|
||||
Loop: {:.2?}
|
||||
Avg time per pair: {:.2?}
|
||||
Total: {:.4?}
|
||||
",
|
||||
file_read,
|
||||
end-file_read,
|
||||
(end-file_read)/(100).try_into().unwrap(),
|
||||
end);
|
||||
}
|
||||
6
2025/3/deadvey/Cargo.toml
Normal file
6
2025/3/deadvey/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "deadvey"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
93
2025/3/deadvey/src/main.rs
Normal file
93
2025/3/deadvey/src/main.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use std::fs;
|
||||
use std::time::Instant;
|
||||
|
||||
fn algorithm(banks: &Vec<&str>) -> (u64, u64)
|
||||
{
|
||||
let bank_length = banks[0].len();
|
||||
let mut total1: u64 = 0;
|
||||
let mut total2: u64 = 0;
|
||||
for bank in banks {
|
||||
let mut prev_index = 0;
|
||||
let mut joltages: [u64; 12] = [0; 12];
|
||||
let mut highest: u64 = 0;
|
||||
let mut overall_index = 0;
|
||||
for i in 0..=11 {
|
||||
for joltage in bank[prev_index..(bank_length-(11-i))].bytes() {
|
||||
overall_index += 1;
|
||||
if joltage == 57 {
|
||||
highest = 9;
|
||||
prev_index = overall_index;
|
||||
break;
|
||||
}
|
||||
let joltage_int = joltage ^ 48; // ASCII mask using XOR (^)
|
||||
if joltage_int as u64 > highest {
|
||||
prev_index = overall_index;
|
||||
highest = joltage_int as u64;
|
||||
}
|
||||
}
|
||||
overall_index = prev_index;
|
||||
joltages[i] = highest as u64;
|
||||
highest = 0;
|
||||
}
|
||||
prev_index = 0;
|
||||
for i in 0..=10 {
|
||||
if joltages[i] > highest.into() {
|
||||
highest = joltages[i] as u64;
|
||||
prev_index = i+1;
|
||||
}
|
||||
}
|
||||
total1 += (highest * 10) as u64;
|
||||
highest = 0;
|
||||
for i in prev_index..=11 {
|
||||
if joltages[i] > highest.into() {
|
||||
highest = joltages[i] as u64;
|
||||
}
|
||||
}
|
||||
total1 += (highest) as u64;
|
||||
total2 += joltages[0] * 10_u64.pow(11)
|
||||
+ joltages[1] * 10_u64.pow(10)
|
||||
+ joltages[2] * 10_u64.pow(9)
|
||||
+ joltages[3] * 10_u64.pow(8)
|
||||
+ joltages[4] * 10_u64.pow(7)
|
||||
+ joltages[5] * 10_u64.pow(6)
|
||||
+ joltages[6] * 10_u64.pow(5)
|
||||
+ joltages[7] * 10_u64.pow(4)
|
||||
+ joltages[8] * 10_u64.pow(3)
|
||||
+ joltages[9] * 10_u64.pow(2)
|
||||
+ joltages[10] * 10_u64
|
||||
+ joltages[11];
|
||||
}
|
||||
|
||||
(total1, total2)
|
||||
}
|
||||
|
||||
// 987654321111111 = 1 bank
|
||||
// 811111111111119
|
||||
// 234234234234278
|
||||
// 818181911112111
|
||||
fn main() {
|
||||
let start = Instant::now();
|
||||
let file_contents: String = fs::read_to_string("../large.txt").unwrap();
|
||||
let mut banks: Vec<&str> = file_contents
|
||||
.split('\n')
|
||||
.collect::<Vec<&str>>();
|
||||
banks.pop();
|
||||
let file_read = start.elapsed();
|
||||
|
||||
let (total1, total2) = algorithm(&banks);
|
||||
let end = start.elapsed();
|
||||
|
||||
let end = start.elapsed();
|
||||
println!("part1: {total1}");
|
||||
println!("part2: {total2}");
|
||||
println!("Times:
|
||||
File read: {:.2?}
|
||||
Loop: {:.2?}
|
||||
Avg time per pair: {:.2?}
|
||||
Total: {:.4?}
|
||||
",
|
||||
file_read,
|
||||
end-file_read,
|
||||
(end-file_read)/(10000).try_into().unwrap(),
|
||||
end);
|
||||
}
|
||||
Reference in New Issue
Block a user