fix clippy lints
This commit is contained in:
parent
6202a3b1fd
commit
fb0bb469ee
|
@ -20,11 +20,11 @@ fn part1(input: &str) -> Result<u64> {
|
||||||
|
|
||||||
for i in 0.. {
|
for i in 0.. {
|
||||||
content.truncate(input.len());
|
content.truncate(input.len());
|
||||||
content.extend(i.to_string().chars());
|
content.push_str(&i.to_string());
|
||||||
|
|
||||||
hasher.input(&content);
|
hasher.input(&content);
|
||||||
let res = hasher.result_reset();
|
let res = hasher.result_reset();
|
||||||
if &res[..2] == &[0, 0] && res[2] <= 0x0f {
|
if res[..2] == [0, 0] && res[2] <= 0x0f {
|
||||||
return Ok(i);
|
return Ok(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,11 @@ fn part2(input: &str) -> Result<u64> {
|
||||||
|
|
||||||
for i in 0.. {
|
for i in 0.. {
|
||||||
content.truncate(input.len());
|
content.truncate(input.len());
|
||||||
content.extend(i.to_string().chars());
|
content.push_str(&i.to_string());
|
||||||
|
|
||||||
hasher.input(&content);
|
hasher.input(&content);
|
||||||
let res = hasher.result_reset();
|
let res = hasher.result_reset();
|
||||||
if &res[..3] == &[0, 0, 0] {
|
if res[..3] == [0, 0, 0] {
|
||||||
return Ok(i);
|
return Ok(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<'a> Iterator for GroupIter<'a> {
|
||||||
type Item = &'a [usize];
|
type Item = &'a [usize];
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.digits.len() == 0 {
|
if self.digits.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ enum Parameter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parameter {
|
impl Parameter {
|
||||||
fn new(mode: i64, val: Option<&i64>) -> Result<Self> {
|
fn new(mode: i64, val: Option<i64>) -> Result<Self> {
|
||||||
let val = *val.ok_or_else(|| err!("parameter value out of bounds"))?;
|
let val = val.ok_or_else(|| err!("parameter value out of bounds"))?;
|
||||||
let mode = mode % 10;
|
let mode = mode % 10;
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
|
@ -54,7 +54,7 @@ impl Parameter {
|
||||||
|
|
||||||
fn get(&self, memory: &[i64]) -> Option<i64> {
|
fn get(&self, memory: &[i64]) -> Option<i64> {
|
||||||
match self {
|
match self {
|
||||||
Parameter::Position(address) => memory.get(*address).map(|v| *v),
|
Parameter::Position(address) => memory.get(*address).copied(),
|
||||||
Parameter::Immediate(value) => Some(*value),
|
Parameter::Immediate(value) => Some(*value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,11 @@ impl Intcode {
|
||||||
let opcode = instruction % 100;
|
let opcode = instruction % 100;
|
||||||
match opcode {
|
match opcode {
|
||||||
1 => {
|
1 => {
|
||||||
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
let op2 = Parameter::new(instruction / 1000, self.memory.get(self.ip + 2))?;
|
let op2 =
|
||||||
let dst = Parameter::new(instruction / 10000, self.memory.get(self.ip + 3))?;
|
Parameter::new(instruction / 1000, self.memory.get(self.ip + 2).copied())?;
|
||||||
|
let dst =
|
||||||
|
Parameter::new(instruction / 10000, self.memory.get(self.ip + 3).copied())?;
|
||||||
|
|
||||||
if let Parameter::Immediate(_) = dst {
|
if let Parameter::Immediate(_) = dst {
|
||||||
Err(err!("add: destination parameter can't be immediate"))
|
Err(err!("add: destination parameter can't be immediate"))
|
||||||
|
@ -129,9 +131,11 @@ impl Intcode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
let op2 = Parameter::new(instruction / 1000, self.memory.get(self.ip + 2))?;
|
let op2 =
|
||||||
let dst = Parameter::new(instruction / 10000, self.memory.get(self.ip + 3))?;
|
Parameter::new(instruction / 1000, self.memory.get(self.ip + 2).copied())?;
|
||||||
|
let dst =
|
||||||
|
Parameter::new(instruction / 10000, self.memory.get(self.ip + 3).copied())?;
|
||||||
|
|
||||||
if let Parameter::Immediate(_) = dst {
|
if let Parameter::Immediate(_) = dst {
|
||||||
Err(err!("multiply: destination parameter can't be immediate"))
|
Err(err!("multiply: destination parameter can't be immediate"))
|
||||||
|
@ -140,7 +144,7 @@ impl Intcode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
3 => {
|
3 => {
|
||||||
let dst = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let dst = Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
|
|
||||||
if let Parameter::Immediate(_) = dst {
|
if let Parameter::Immediate(_) = dst {
|
||||||
Err(err!("input: destination parameter can't be immediate"))
|
Err(err!("input: destination parameter can't be immediate"))
|
||||||
|
@ -149,26 +153,32 @@ impl Intcode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4 => {
|
4 => {
|
||||||
let op = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let op = Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
|
|
||||||
Ok(Opcode::Output(op))
|
Ok(Opcode::Output(op))
|
||||||
}
|
}
|
||||||
5 => {
|
5 => {
|
||||||
let test = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let test =
|
||||||
let dst = Parameter::new(instruction / 1000, self.memory.get(self.ip + 2))?;
|
Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
|
let dst =
|
||||||
|
Parameter::new(instruction / 1000, self.memory.get(self.ip + 2).copied())?;
|
||||||
|
|
||||||
Ok(Opcode::JumpTrue(test, dst))
|
Ok(Opcode::JumpTrue(test, dst))
|
||||||
}
|
}
|
||||||
6 => {
|
6 => {
|
||||||
let test = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let test =
|
||||||
let dst = Parameter::new(instruction / 1000, self.memory.get(self.ip + 2))?;
|
Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
|
let dst =
|
||||||
|
Parameter::new(instruction / 1000, self.memory.get(self.ip + 2).copied())?;
|
||||||
|
|
||||||
Ok(Opcode::JumpFalse(test, dst))
|
Ok(Opcode::JumpFalse(test, dst))
|
||||||
}
|
}
|
||||||
7 => {
|
7 => {
|
||||||
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
let op2 = Parameter::new(instruction / 1000, self.memory.get(self.ip + 2))?;
|
let op2 =
|
||||||
let dst = Parameter::new(instruction / 10000, self.memory.get(self.ip + 3))?;
|
Parameter::new(instruction / 1000, self.memory.get(self.ip + 2).copied())?;
|
||||||
|
let dst =
|
||||||
|
Parameter::new(instruction / 10000, self.memory.get(self.ip + 3).copied())?;
|
||||||
|
|
||||||
if let Parameter::Immediate(_) = dst {
|
if let Parameter::Immediate(_) = dst {
|
||||||
Err(err!("less than: destination parameter can't be immediate"))
|
Err(err!("less than: destination parameter can't be immediate"))
|
||||||
|
@ -177,9 +187,11 @@ impl Intcode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
8 => {
|
8 => {
|
||||||
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1))?;
|
let op1 = Parameter::new(instruction / 100, self.memory.get(self.ip + 1).copied())?;
|
||||||
let op2 = Parameter::new(instruction / 1000, self.memory.get(self.ip + 2))?;
|
let op2 =
|
||||||
let dst = Parameter::new(instruction / 10000, self.memory.get(self.ip + 3))?;
|
Parameter::new(instruction / 1000, self.memory.get(self.ip + 2).copied())?;
|
||||||
|
let dst =
|
||||||
|
Parameter::new(instruction / 10000, self.memory.get(self.ip + 3).copied())?;
|
||||||
|
|
||||||
if let Parameter::Immediate(_) = dst {
|
if let Parameter::Immediate(_) = dst {
|
||||||
Err(err!("equals: destination parameter can't be immediate"))
|
Err(err!("equals: destination parameter can't be immediate"))
|
||||||
|
|
Loading…
Reference in a new issue