Skip to content

Commit 746d5a1

Browse files
committed
[2024] Fix clippy lints
1 parent 27731a1 commit 746d5a1

File tree

4 files changed

+17
-57
lines changed

4 files changed

+17
-57
lines changed

aoc_2024/src/day_13.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use aoc_lib::vector::AsTuple2;
1+
use aoc_lib::vector::IntoTuple2;
22
use common::{solution, Answer};
33
use nd_vec::{vector, Vec2};
44

@@ -24,7 +24,7 @@ struct Case {
2424

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

aoc_2024/src/day_17.rs

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,17 @@ fn part_a(input: &str) -> Answer {
2121
}
2222

2323
fn part_b(_input: &str) -> Answer {
24-
// {
25-
// let mut processor = processor.clone();
26-
// *processor.reg_mut(0) = 1234;
27-
28-
// while let Some(ins) = processor.next_instruction() {
29-
// ins.opcode.debug(&processor, ins.argument.clone());
30-
// ins.opcode.evaluate(&mut processor, ins.argument);
31-
// }
32-
33-
// println!("{processor:?}");
34-
// }
35-
36-
// while a != 0 {
37-
// b = a % 8;
38-
// b = b ^ 2;
39-
// c = a.wrapping_shr(b as u32);
40-
// b = b ^ c;
41-
// b = b ^ 3;
42-
// dbg!(b % 8);
43-
// a = a.wrapping_shr(3);
44-
// }
45-
46-
// while a != 0 {
47-
// dbg!((((a % 8) ^ 2) ^ a.wrapping_shr((a % 8) as u32 ^ 2) ^ 3) % 8);
48-
// a = a.wrapping_shr(3);
49-
// }
24+
// There is no way to make a general solution to this problem, so we have to
25+
// rever engineer our specific input. In my case the input program
26+
// translates into the following, where x is the input to the first
27+
// register.
28+
//
29+
// (((x % 8) ^ 2) ^ x.wrapping_shr((x % 8) as u32 ^ 2) ^ 3) % 8
30+
//
31+
// Because an input can cause multiple outputs, we then use a recursive
32+
// solver to create the needed input three bits at a time.
5033

5134
let exp = [2, 4, 1, 2, 7, 5, 4, 7, 1, 3, 5, 5, 0, 3, 3, 0];
52-
// let mut out = 0;
53-
54-
// for exp in [2, 4] {
55-
// for x in 0..=u64::MAX {
56-
// // let val = ((x ^ 2) ^ x.wrapping_shr(x as u32 ^ 2) ^ 3) % 8;
57-
// let val = (((x % 8) ^ 2) ^ x.wrapping_shr((x % 8) as u32 ^ 2) ^ 3) % 8;
58-
// println!("{x}: {val}");
59-
// if val == exp {
60-
// println!("{x}");
61-
// out <<= 3;
62-
// out |= x;
63-
// break;
64-
// }
65-
// }
66-
// }
6735

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

162-
fn new(program: Vec<u64>) -> Self {
163-
Self {
164-
registers: [0, 0, 0],
165-
program,
166-
ptr: 0,
167-
output: Vec::new(),
168-
}
169-
}
170-
171130
fn reg(&self, reg: u64) -> u64 {
172131
self.registers[reg as usize]
173132
}
@@ -222,6 +181,7 @@ impl OpCode {
222181
}
223182
}
224183

184+
#[allow(unused)]
225185
fn debug(&self, proc: &Processor, (combo, literal): (Option<Argument>, u64)) {
226186
match self {
227187
OpCode::Adv => println!("A = A >> {:?}", combo.unwrap()),

aoc_2024/src/day_20.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::VecDeque, convert::identity, u32};
1+
use std::{collections::VecDeque, convert::identity};
22

33
use aoc_lib::{direction::cardinal::Direction, matrix::Grid};
44
use common::{solution, Answer};

aoc_lib/src/vector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use nd_vec::Vec2;
22

3-
pub trait AsTuple2<T> {
4-
fn as_tuple(self) -> (T, T);
3+
pub trait IntoTuple2<T> {
4+
fn into_tuple(self) -> (T, T);
55
}
6-
impl<T: Copy> AsTuple2<T> for Vec2<T> {
7-
fn as_tuple(self) -> (T, T) {
6+
impl<T: Copy> IntoTuple2<T> for Vec2<T> {
7+
fn into_tuple(self) -> (T, T) {
88
(self.x(), self.y())
99
}
1010
}

0 commit comments

Comments
 (0)