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(())
}
struct XMASDecoder {
pub struct XMASDecoder {
input: Vec<i64>,
}
@ -36,17 +36,17 @@ impl TryFrom<&str> for 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() {
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);
}
}
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 sum = 0;
for i in slice {
@ -61,7 +61,7 @@ impl XMASDecoder {
None
}
fn decode(&self) -> Option<i64> {
pub fn decode(&self) -> Option<i64> {
self.input
.windows(26)
.into_iter()
@ -83,7 +83,7 @@ impl XMASDecoder {
}
#[derive(Error, Debug)]
enum Errors {
pub enum Errors {
#[error("invalid input")]
InvalidInput,
}