diff --git a/2022/day01-part1/src/main.rs b/2022/day01-part1/src/main.rs index b36706c..f2f4255 100644 --- a/2022/day01-part1/src/main.rs +++ b/2022/day01-part1/src/main.rs @@ -8,7 +8,7 @@ fn main() { // Next, read the contents of the input file into a string for easier processing. let input = std::fs::read_to_string(&args[1]).expect("Error opening file"); // Line-by-line processing is easiest. - let mut input = input.lines(); + let input = input.lines(); // --- TASK BEGIN --- @@ -17,7 +17,7 @@ fn main() { let mut cals = 0u32; // Iterate line-by-line. - while let Some(line) = input.next() { + for line in input { // println!("Line is: {line}"); match line.parse::() { Ok(num) => cals += num, diff --git a/2022/day01-part2/src/main.rs b/2022/day01-part2/src/main.rs index f732d1c..3d50d2c 100644 --- a/2022/day01-part2/src/main.rs +++ b/2022/day01-part2/src/main.rs @@ -8,7 +8,7 @@ fn main() { // Next, read the contents of the input file into a string for easier processing. let input = std::fs::read_to_string(&args[1]).expect("Error opening file"); // Line-by-line processing is easiest. - let mut input = input.lines(); + let input = input.lines(); // --- TASK BEGIN --- @@ -17,7 +17,7 @@ fn main() { let mut cals = 0u32; // Iterate line-by-line. - while let Some(line) = input.next() { + for line in input { match line.parse::() { Ok(num) => cals += num, Err(_) => { diff --git a/2022/day02-part1/src/main.rs b/2022/day02-part1/src/main.rs index 5eaa518..a1b2132 100644 --- a/2022/day02-part1/src/main.rs +++ b/2022/day02-part1/src/main.rs @@ -19,14 +19,14 @@ fn main() { // Next, read the contents of the input file into a string for easier processing. let input = std::fs::read_to_string(&args[1]).expect("Error opening file"); // Line-by-line processing is easiest. - let mut input = input.lines(); + let input = input.lines(); // --- TASK BEGIN --- let mut total_score = 0; - while let Some(line) = input.next() { + for line in input { // Translate the line's first character into its respective shape. - let opponent_shape = match line.chars().nth(0) { + let opponent_shape = match line.chars().next() { Some('A') => Rock, Some('B') => Paper, Some('C') => Scissors, diff --git a/2022/day02-part2/src/main.rs b/2022/day02-part2/src/main.rs index 0a9fc6b..cb853b7 100644 --- a/2022/day02-part2/src/main.rs +++ b/2022/day02-part2/src/main.rs @@ -27,14 +27,14 @@ fn main() { // Next, read the contents of the input file into a string for easier processing. let input = std::fs::read_to_string(&args[1]).expect("Error opening file"); // Line-by-line processing is easiest. - let mut input = input.lines(); + let input = input.lines(); // --- TASK BEGIN --- let mut total_score = 0; - while let Some(line) = input.next() { + for line in input { // Translate the line's first character into its respective shape. - let opponent_shape = match line.chars().nth(0) { + let opponent_shape = match line.chars().next() { Some('A') => Rock, Some('B') => Paper, Some('C') => Scissors,