more cleanup

- fix all clippy warnings
- add times(n: usize) iterator

Signed-off-by: Stephen Waits <swaits@amazon.com>
This commit is contained in:
Stephen Waits committed 2020-12-12 07:10:10 -08:00
1 parent 16670f26a5
commit 8fb67d653c
6 files changed
+46 -56

No files matched your search

+3 -3
View File
@@ -3,7 +3,7 @@
use crate::utils;
use anyhow::{anyhow, Result};
fn is_bad(data: &Vec<i64>, n: usize, i: usize) -> Result<i64> {
fn is_bad(data: &[i64], n: usize, i: usize) -> Result<i64> {
let prev_n = &data[i - n..i];
if !utils::combinations(2, prev_n.len()).any(|c| data[i] == prev_n[c[0]] + prev_n[c[1]]) {
Ok(data[i])
@@ -12,7 +12,7 @@ fn is_bad(data: &Vec<i64>, n: usize, i: usize) -> Result<i64> {
}
}
fn find_first_bad(data: &Vec<i64>, n: usize, start: usize) -> Result<i64> {
fn find_first_bad(data: &[i64], n: usize, start: usize) -> Result<i64> {
for i in start..data.len() {
let ret = is_bad(data, n, i);
if ret.is_ok() {
@@ -22,7 +22,7 @@ fn find_first_bad(data: &Vec<i64>, n: usize, start: usize) -> Result<i64> {
Err(anyhow!("no result found"))
}
fn find_contiguous_set(data: &Vec<i64>, x: i64) -> Result<i64> {
fn find_contiguous_set(data: &[i64], x: i64) -> Result<i64> {
for set_size in 2..data.len() - 1 {
for i in 0..data.len() - set_size {
if data[i..i + set_size].iter().sum::<i64>() == x {