Skip to content

Commit

Permalink
[2024] Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Dec 22, 2024
1 parent 27731a1 commit 746d5a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 57 deletions.
4 changes: 2 additions & 2 deletions aoc_2024/src/day_13.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aoc_lib::vector::AsTuple2;
use aoc_lib::vector::IntoTuple2;
use common::{solution, Answer};
use nd_vec::{vector, Vec2};

Expand All @@ -24,7 +24,7 @@ struct Case {

impl Case {
fn cheapest(&self) -> u64 {
let cast = |x: Vec2<u64>| x.try_cast::<i64>().unwrap().as_tuple();
let cast = |x: Vec2<u64>| x.try_cast::<i64>().unwrap().into_tuple();
let ((gx, gy), (ax, ay), (bx, by)) =
(cast(self.goal), cast(self.a_button), cast(self.b_button));

Expand Down
60 changes: 10 additions & 50 deletions aoc_2024/src/day_17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,17 @@ fn part_a(input: &str) -> Answer {
}

fn part_b(_input: &str) -> Answer {
// {
// let mut processor = processor.clone();
// *processor.reg_mut(0) = 1234;

// while let Some(ins) = processor.next_instruction() {
// ins.opcode.debug(&processor, ins.argument.clone());
// ins.opcode.evaluate(&mut processor, ins.argument);
// }

// println!("{processor:?}");
// }

// while a != 0 {
// b = a % 8;
// b = b ^ 2;
// c = a.wrapping_shr(b as u32);
// b = b ^ c;
// b = b ^ 3;
// dbg!(b % 8);
// a = a.wrapping_shr(3);
// }

// while a != 0 {
// dbg!((((a % 8) ^ 2) ^ a.wrapping_shr((a % 8) as u32 ^ 2) ^ 3) % 8);
// a = a.wrapping_shr(3);
// }
// There is no way to make a general solution to this problem, so we have to
// rever engineer our specific input. In my case the input program
// translates into the following, where x is the input to the first
// register.
//
// (((x % 8) ^ 2) ^ x.wrapping_shr((x % 8) as u32 ^ 2) ^ 3) % 8
//
// Because an input can cause multiple outputs, we then use a recursive
// solver to create the needed input three bits at a time.

let exp = [2, 4, 1, 2, 7, 5, 4, 7, 1, 3, 5, 5, 0, 3, 3, 0];
// let mut out = 0;

// for exp in [2, 4] {
// for x in 0..=u64::MAX {
// // let val = ((x ^ 2) ^ x.wrapping_shr(x as u32 ^ 2) ^ 3) % 8;
// let val = (((x % 8) ^ 2) ^ x.wrapping_shr((x % 8) as u32 ^ 2) ^ 3) % 8;
// println!("{x}: {val}");
// if val == exp {
// println!("{x}");
// out <<= 3;
// out |= x;
// break;
// }
// }
// }

fn solve(exp: &[u64], n: usize, a: u64) -> u64 {
for inp in 0..=0b111u64 {
Expand Down Expand Up @@ -159,15 +127,6 @@ impl Processor {
}
}

fn new(program: Vec<u64>) -> Self {
Self {
registers: [0, 0, 0],
program,
ptr: 0,
output: Vec::new(),
}
}

fn reg(&self, reg: u64) -> u64 {
self.registers[reg as usize]
}
Expand Down Expand Up @@ -222,6 +181,7 @@ impl OpCode {
}
}

#[allow(unused)]
fn debug(&self, proc: &Processor, (combo, literal): (Option<Argument>, u64)) {
match self {
OpCode::Adv => println!("A = A >> {:?}", combo.unwrap()),
Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_20.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::VecDeque, convert::identity, u32};
use std::{collections::VecDeque, convert::identity};

use aoc_lib::{direction::cardinal::Direction, matrix::Grid};
use common::{solution, Answer};
Expand Down
8 changes: 4 additions & 4 deletions aoc_lib/src/vector.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use nd_vec::Vec2;

pub trait AsTuple2<T> {
fn as_tuple(self) -> (T, T);
pub trait IntoTuple2<T> {
fn into_tuple(self) -> (T, T);
}
impl<T: Copy> AsTuple2<T> for Vec2<T> {
fn as_tuple(self) -> (T, T) {
impl<T: Copy> IntoTuple2<T> for Vec2<T> {
fn into_tuple(self) -> (T, T) {
(self.x(), self.y())
}
}

0 comments on commit 746d5a1

Please sign in to comment.