diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 25 | ||||
-rw-r--r-- | src/main.rs | 5 |
2 files changed, 18 insertions, 12 deletions
@@ -5,11 +5,11 @@ use std::collections::LinkedList; use chrono::NaiveDate; use chrono::Duration; -pub fn partition (f: &Fn(u32) -> i64, v: &Vec<i64>) -> LinkedList<LinkedList<i64>> { +pub fn partition(f: &Fn(u32) -> i64, v: &Vec<i64>) -> LinkedList<LinkedList<i64>> { let mut term: LinkedList<i64> = LinkedList::new(); let mut res: LinkedList<LinkedList<i64>> = LinkedList::new(); - let mut n : u32 = 1; - let mut a : i64 = v[0]; + let mut n: u32 = 1; + let mut a: i64 = v[0]; for &i in v.iter() { while i >= a + f(n) { @@ -25,7 +25,10 @@ pub fn partition (f: &Fn(u32) -> i64, v: &Vec<i64>) -> LinkedList<LinkedList<i64 res } -pub fn partition_days (f: &Fn(u32) -> i64, days: &Vec<NaiveDate>) -> LinkedList<LinkedList<NaiveDate>> { +pub fn partition_days( + f: &Fn(u32) -> i64, + days: &Vec<NaiveDate>, +) -> LinkedList<LinkedList<NaiveDate>> { let day1 = days[0]; let part; @@ -33,7 +36,7 @@ pub fn partition_days (f: &Fn(u32) -> i64, days: &Vec<NaiveDate>) -> LinkedList< let mut v: Vec<i64> = Vec::with_capacity(days.len()); for &d in days.iter() { - v.push((day1-d).num_days()); + v.push((day1 - d).num_days()); } v.sort_unstable(); v.dedup(); @@ -41,10 +44,14 @@ pub fn partition_days (f: &Fn(u32) -> i64, days: &Vec<NaiveDate>) -> LinkedList< part = partition(f, &v); } - let res = part.into_iter().map( - |l| l.into_iter().map( - |d| day1 - Duration::days(d)).rev().collect() - ).collect(); + let res = part.into_iter() + .map(|l| { + l.into_iter() + .map(|d| day1 - Duration::days(d)) + .rev() + .collect() + }) + .collect(); res } diff --git a/src/main.rs b/src/main.rs index 8bf737a..752204c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,8 +30,8 @@ struct Args { arg_day: Vec<NaiveDate>, } -fn exponent(b:f32, n:u32) -> i64 { - let i : i32 = n as i32 - 1; +fn exponent(b: f32, n: u32) -> i64 { + let i: i32 = n as i32 - 1; b.powi(i).ceil() as i64 } @@ -67,4 +67,3 @@ fn main() { exit(1); } } - |