Compare commits

..

1 commit

Author SHA1 Message Date
decff21434 day9 2020-12-16 23:16:38 +01:00

View file

@ -19,7 +19,7 @@ fn main() -> Result<()> {
Ok(()) Ok(())
} }
struct XMASDecoder { pub struct XMASDecoder {
input: Vec<i64>, input: Vec<i64>,
} }
@ -36,17 +36,17 @@ impl TryFrom<&str> for XMASDecoder {
} }
impl XMASDecoder { impl XMASDecoder {
fn find_continues(&self, target: i64) -> Option<&[i64]> { pub fn find_continues(&self, target: i64) -> Option<&[i64]> {
for offset in 0..self.input.len() { for offset in 0..self.input.len() {
let slice = &self.input[offset..self.input.len()]; let slice = &self.input[offset..self.input.len()];
if let Some(found) = Self::find_sum(slice, target) { if let Some(found) = Self::find_sum_slice(slice, target) {
return Some(found); return Some(found);
} }
} }
None None
} }
fn find_sum(slice: &[i64], target: i64) -> Option<&[i64]> { fn find_sum_slice(slice: &[i64], target: i64) -> Option<&[i64]> {
let mut offset = 0; let mut offset = 0;
let mut sum = 0; let mut sum = 0;
for i in slice { for i in slice {
@ -61,7 +61,7 @@ impl XMASDecoder {
None None
} }
fn decode(&self) -> Option<i64> { pub fn decode(&self) -> Option<i64> {
self.input self.input
.windows(26) .windows(26)
.into_iter() .into_iter()
@ -83,7 +83,7 @@ impl XMASDecoder {
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
enum Errors { pub enum Errors {
#[error("invalid input")] #[error("invalid input")]
InvalidInput, InvalidInput,
} }