cleanup and ignore input

This commit is contained in:
2025-12-14 23:23:13 +01:00
parent c40d446b11
commit 6919b7abf8
8 changed files with 3 additions and 77 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target
/input/

View File

@@ -6,14 +6,6 @@ use microlp::{ComparisonOp, OptimizationDirection, Problem, Variable};
#[aoc(day10, part1)]
pub fn part1(input: &str) -> u32 {
let machines = parse(input);
// for machine in &machines {
// println!(
// "num buttons: {} num lights: {} diff: {}",
// machine.buttons.len(),
// machine.lights.len(),
// machine.buttons.len() as i32 - machine.lights.len() as i32
// );
// }
machines.into_iter().map(|m| m.button_presses()).sum()
}
@@ -32,9 +24,7 @@ struct Machine {
impl Machine {
fn joltage_presses(self: Machine) -> u32 {
// Method: Set up a linear set of equations A^Tx=b, where A contains
// the coordinates of the buttons (one row per button) plus coordinates
// associated with optimisation parameters; or use a milp library :)
// using microlp's milp implementation... TODO: manual gauss elimination?
let mut problem = Problem::new(OptimizationDirection::Minimize);
let vars: Vec<Variable> = (0..self.buttons.len())
.map(|_| problem.add_integer_var(1.0, (0, *self.joltage.iter().max().unwrap() as i32)))
@@ -51,8 +41,6 @@ impl Machine {
);
}
println!("{:?}", problem);
problem
.solve()
.unwrap()

View File

@@ -46,21 +46,6 @@ fn invalid_ids_2(ranges: Vec<(&str, &str)>) -> u64 {
}
}
}
// if from.len() == to.len() {
// println!("{} to {}", from, to,);
// for n in (2..=(from.len() / 2).max(2)).filter(|n| from.len() % n == 0) {
// //println!("{}", n);
// let l = from.len() / n;
// for num in from[..l].parse::<u64>().unwrap()..=to[..l].parse::<u64>().unwrap() {
// let candidate = num.to_string().repeat(n).parse::<u64>().unwrap();
// println!("{}", candidate);
// if candidate <= i_to && candidate >= i_from {
// println!("selected!");
// result.insert(candidate);
// }
// }
// }
// }
}
result.iter().sum()
}
@@ -73,7 +58,6 @@ fn invalid_ids(ranges: Vec<(&str, &str)>) -> Vec<u64> {
let i_str = i.to_string();
let i_len = i_str.len();
if i_len % 2 == 0 {
//println!("{}: {}-{}", i, &i_str[..i_len / 2], &i_str[i_len / 2..]);
if i_str[..i_len / 2] == i_str[i_len / 2..] {
result.push(i);
}

View File

@@ -27,7 +27,6 @@ fn make_array(input: &str) -> Vec<Vec<u8>> {
}
}
}
// println!("{:?}", array);
array
}
@@ -51,7 +50,6 @@ fn get_accessible(array: &Vec<Vec<u8>>) -> Vec<Vec<u8>> {
< 4) as u8;
}
}
// println!("{:?}", accessible);
accessible
}

View File

@@ -18,30 +18,6 @@ impl UintInclusiveRange {
value >= self.start && value <= self.end
}
// fn overlaps(&self, other: &UintInclusiveRange) -> bool {
// (self.start >= other.start && self.start <= other.end)
// || (self.end >= other.start && self.end <= other.end)
// || (self.start <= other.start && self.end >= other.end)
// || (self.start >= other.start && self.end <= other.end)
// }
// fn join(&self, other: &UintInclusiveRange) -> UintInclusiveRange {
// println!(
// "Joining {:?} and {:?} into {:?}",
// self,
// other,
// UintInclusiveRange::new(
// cmp::min(self.start, other.start),
// cmp::max(self.end, other.end),
// )
// );
// assert!(self.overlaps(&other));
// UintInclusiveRange::new(
// cmp::min(self.start, other.start),
// cmp::max(self.end, other.end),
// )
// }
fn size(self) -> u64 {
self.end - self.start + 1
}

View File

@@ -20,8 +20,6 @@ fn run(input: &str) -> (u32, u64) {
let local_split;
(beams, local_split) = propagate(&field_slice, beams);
split_count = split_count + local_split;
//println!("{}", split_count);
println!("{:?}", beams);
}
let timeline_count = beams.values().sum();
(split_count, timeline_count)
@@ -38,7 +36,6 @@ fn parse(input: &str) -> Vec<Vec<(usize, TachyonPoint)>> {
let mut fieldmap: Vec<Vec<(usize, TachyonPoint)>> = vec![Vec::new(); lines.clone().count()];
for (i, line) in lines.enumerate() {
// println!("{}", line);
for (j, c) in line.chars().enumerate() {
match c {
'S' => fieldmap[i].push((j, TachyonPoint::Source)),

View File

@@ -14,7 +14,6 @@ pub fn part2(input: &str) -> i64 {
let nodes = parse(input);
let distance_matrix = distances(nodes.clone());
let last_nodes = fully_connect(distance_matrix).unwrap();
println!("{:?}", last_nodes);
nodes[last_nodes.0][0] * nodes[last_nodes.1][0]
}
@@ -64,7 +63,6 @@ fn make_circuits(distance_matrix: Vec<Vec<f64>>, n_connections: u32) -> Vec<Hash
let (to_merge, mut existing): (Vec<HashSet<usize>>, Vec<HashSet<usize>>) = circuits
.into_iter()
.partition(|c| c.contains(i) || c.contains(&(*j + 1 + *i)));
// println!("{:?} {} {}", i, j + 1 + i, d);
assert!(to_merge.len() < 3);
let new_circuit: HashSet<usize> = to_merge
.iter()

View File

@@ -7,9 +7,7 @@ pub fn part1(input: &str) -> i64 {
let mut area = 0;
for (x1, y1) in coords.iter().rev().take(10) {
for (x2, y2) in coords.iter().take(10) {
if ((x1 - x2 + 1) * (y1 - y2 + 1)) > area {
println!("{:?}", ((x1, y1), (x2, y2)))
};
if ((x1 - x2 + 1) * (y1 - y2 + 1)) > area {};
area = area.max((x1 - x2 + 1) * (y1 - y2 + 1));
}
}
@@ -50,13 +48,6 @@ fn check(corner_1: usize, corner_3: usize, coords: &Vec<(i64, i64)>) -> bool {
|| (x1 <= &upper_left.0 && x2 <= &upper_left.0)
|| (x1 >= &lower_right.0 && x2 >= &lower_right.0))
{
// println!(
// "rejected horizontal of {:?},{:?} due to line {:?} {:?}",
// upper_left,
// lower_right,
// (x1, y1),
// (x2, y2)
// );
return false;
}
} else {
@@ -66,13 +57,6 @@ fn check(corner_1: usize, corner_3: usize, coords: &Vec<(i64, i64)>) -> bool {
|| (y1 <= &upper_left.1 && y2 <= &upper_left.1)
|| (y1 >= &lower_right.1 && y2 >= &lower_right.1))
{
// println!(
// "rejected vertical of {:?},{:?} due to line {:?} {:?}",
// upper_left,
// lower_right,
// (x1, y1),
// (x2, y2)
// );
return false;
}
}