Compare commits
1 commit
0178a91648
...
decff21434
Author | SHA1 | Date | |
---|---|---|---|
decff21434 |
1 changed files with 6 additions and 6 deletions
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue