diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-12-05 13:15:03 +0100 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-12-05 13:15:03 +0100 |
commit | d38746c3b68f139fb2f6df78a219c2577fc0338c (patch) | |
tree | bf51edf668f9054ea8b3c28aa6043061ad136d83 /2018/src/day1.rs | |
parent | d139374ef1518c5bd4e5c84e1d88263fdda2e15c (diff) |
Day 5 + benchmarking
Diffstat (limited to '2018/src/day1.rs')
-rw-r--r-- | 2018/src/day1.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/2018/src/day1.rs b/2018/src/day1.rs index 741f5b3..b86387b 100644 --- a/2018/src/day1.rs +++ b/2018/src/day1.rs @@ -2,11 +2,11 @@ use std::io; use std::io::BufRead; use std::collections::HashSet; -pub fn main<T: BufRead>(reader: T) -> io::Result<()> { +pub fn main<T: BufRead>(reader: T) -> io::Result<(String, String)> { let values: Vec<i64> = reader.lines().map(|l| l.unwrap().parse::<i64>().unwrap()).collect(); - println!("{}", values.iter().sum::<i64>()); + let part1 = values.iter().sum::<i64>(); let mut seen = HashSet::new(); seen.insert(0); @@ -15,11 +15,11 @@ pub fn main<T: BufRead>(reader: T) -> io::Result<()> { for val in values.iter().cycle() { res += val; if seen.contains(&res) { - println!("{}", res); - return Ok(()); + return Ok((part1.to_string(), res.to_string())); } else { seen.insert(res); } } - unreachable!() + + Err(io::Error::new(io::ErrorKind::Other, "Invalid input")) } |