2016, 2017, 2018, 2024 puzzle progress

This commit is contained in:
2025-10-08 13:17:46 -04:00
parent af075edb24
commit e1bdbe21c8
21 changed files with 3658 additions and 43 deletions
+5 -10
View File
@@ -16,7 +16,11 @@ fn main() {
let direction_val : i32 = velocity.parse().unwrap();
match direction {
"+" => {
working_value += direction_val;
let destination = working_value + direction_val;
for index in working_value..destination {
println!("At {index}");
}
working_value = destination;
}
"-" => {
working_value -= direction_val;
@@ -25,15 +29,6 @@ fn main() {
unreachable!("Invalid direction");
}
}
println!("||{working_value}||\t");
if let Some(found) = visited_locations.get(&working_value) {
println!("GET SUCCESS -> {working_value} / {found}");
break;
}
for index in 0..working_value.abs() {
println!("Adding visit to {}", index + working_value);
visited_locations.insert(index + working_value, 0);
}
}
}
// BROKEN
+62
View File
@@ -0,0 +1,62 @@
use core::read_data;
struct MovingPoint {
position_x: i32,
position_y: i32,
velocity_x: i32,
velocity_y: i32
}
impl MovingPoint {
fn current_position(&self) -> (i32, i32) {
(self.position_x, self.position_y)
}
fn current_velocity(&self) -> (i32, i32) {
(self.velocity_x, self.velocity_y)
}
fn tick(&mut self) {
self.position_x += self.velocity_x;
self.position_y += self.velocity_y;
}
// parse line like
// position=<-2, 3> velocity=< 1, 0>
fn parse(input: &str) -> Self {
let (_, balance) = input.split_once("=").unwrap();
let (pos_parts, vel_balance) = balance.split_once(">").unwrap();
let (pos_x, pos_y) = pos_parts.split_once(",").unwrap();
let (_, vel_balance) = vel_balance.split_once("=").unwrap();
let (vel_x, vel_y) = vel_balance.split_once(",").unwrap();
let position_x = pos_x.clone()[1..].trim().parse::<i32>().unwrap();
let position_y = pos_y.trim().parse::<i32>().unwrap();
let velocity_x = vel_x.clone()[1..].trim().parse::<i32>().unwrap();
let velocity_y = vel_y[0..(vel_y.len() - 1)].trim().parse::<i32>().unwrap();
MovingPoint {
position_x,
position_y,
velocity_x,
velocity_y,
}
}
}
fn main() {
let mut points = vec![];
let binding = read_data("2018_10_data_SAMPLE.txt");
let lines = binding.lines();
for line in lines {
// println!("Input: [[{line}]]");
let parsed = MovingPoint::parse(line);
points.push(parsed);
}
println!("Loaded {} points. Preparing to move them.", points.len());
for mut point in points {
point.tick()
}
}