[2017][rust][2.x]
change tvuzqpvsoymulynxxlwxoxznwzzlmuut
commit 3855453e62161768aecedb33400f5d36112cf467
author Alpha Chen <alpha.chen@gmail.com>
date
parent mrssttlo
diff --git a/2017/rust/src/day_01.rs b/2017/rust/src/day_01.rs
index 61971a6..fdd0cd2 100644
--- a/2017/rust/src/day_01.rs
+++ b/2017/rust/src/day_01.rs
@@ -1,5 +1,6 @@
 use failure::*;
 
+#[allow(dead_code)]
 pub fn solve(input: &str) -> Result<String, Error> {
     let input: Vec<u32> = input
         .trim()
diff --git a/2017/rust/src/day_02.rs b/2017/rust/src/day_02.rs
index 2eafa08..f8d495a 100644
--- a/2017/rust/src/day_02.rs
+++ b/2017/rust/src/day_02.rs
@@ -4,16 +4,20 @@ pub fn solve(input: &str) -> Result<String, Error> {
     Ok(
         input
             .trim()
-            .split("\n")
+            .split('\n')
             .map(|row| {
-                let row: Vec<_> = row.split("\t")
+                row.split('\t')
                     .map(|x| x.parse::<usize>().unwrap())
-                    .collect();
-                let min = row.iter().min().unwrap();
-                let max = row.iter().max().unwrap();
-                max - min
+                    .collect::<Vec<_>>()
             })
+            .map(|row| checksum(&row))
             .sum::<usize>()
             .to_string(),
     )
 }
+
+fn checksum(row: &[usize]) -> usize {
+    let min = row.iter().min().unwrap();
+    let max = row.iter().max().unwrap();
+    max - min
+}