From 00063359d3bd27331b35995b05749764e40b20ec Mon Sep 17 00:00:00 2001 From: Codinget Date: Mon, 5 Dec 2022 19:48:08 +0000 Subject: [PATCH] rustfmt --- d2/src/main.rs | 16 +++++++++++----- d3/src/main.rs | 21 ++++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/d2/src/main.rs b/d2/src/main.rs index 17382fe..5cb2264 100644 --- a/d2/src/main.rs +++ b/d2/src/main.rs @@ -15,7 +15,7 @@ impl RPS { 'A' | 'X' => Rock, 'B' | 'Y' => Paper, 'C' | 'Z' => Scissor, - _ => panic!() + _ => panic!(), } } pub fn score(self) -> u32 { @@ -48,7 +48,7 @@ impl Outcome { 'X' => Loss, 'Y' => Draw, 'Z' => Win, - _ => panic!() + _ => panic!(), } } @@ -56,7 +56,7 @@ impl Outcome { match self { Win => 6, Draw => 3, - Loss => 0 + Loss => 0, } } @@ -73,9 +73,15 @@ fn main() -> Result<(), Error> { let mut total_score_p1 = 0; let mut total_score_p2 = 0; for line in read_to_string("input.txt")?.split("\n") { - if line.is_empty() { continue } + if line.is_empty() { + continue; + } let (opponent, you) = (line.chars().nth(0).unwrap(), line.chars().nth(2).unwrap()); - let (opponent, your_move, outcome) = (RPS::from_char(opponent), RPS::from_char(you), Outcome::from_char(you)); + let (opponent, your_move, outcome) = ( + RPS::from_char(opponent), + RPS::from_char(you), + Outcome::from_char(you), + ); let score_p1 = your_move.score() + RPS::outcome(opponent, your_move).score(); total_score_p1 += score_p1; let score_p2 = outcome.score() + outcome.for_opponent(opponent).score(); diff --git a/d3/src/main.rs b/d3/src/main.rs index ec67cd3..441d9b9 100644 --- a/d3/src/main.rs +++ b/d3/src/main.rs @@ -1,10 +1,10 @@ -use std::{io::Result, fs::read_to_string, collections::HashSet}; +use std::{collections::HashSet, fs::read_to_string, io::Result}; pub fn priority(x: u8) -> u32 { (match x { 0x61..=0x7a => x - 0x61 + 1, 0x41..=0x5a => x - 0x41 + 27, - _ => unreachable!() + _ => unreachable!(), }) as u32 } @@ -16,19 +16,30 @@ fn main() -> Result<()> { let mut elves: Vec> = Vec::new(); for line in read_to_string("input.txt")?.split("\n") { - if line.is_empty() { continue; } + if line.is_empty() { + continue; + } let bytes = line.as_bytes(); let (first_half, second_half) = bytes.split_at(bytes.len() / 2); let in_first_half = first_half.iter().copied().collect::>(); let in_second_half = second_half.iter().copied().collect::>(); - let in_both_halves = in_first_half.intersection(&in_second_half).copied().next().unwrap(); + let in_both_halves = in_first_half + .intersection(&in_second_half) + .copied() + .next() + .unwrap(); p1_priority += priority(in_both_halves); let items = bytes.iter().copied().collect::>(); elves.push(items.clone()); if i == 2 { - let badge = items.iter().filter(|item| elves.iter().filter(|elf| elf.contains(item)).count() == 3).copied().next().unwrap(); + let badge = items + .iter() + .filter(|item| elves.iter().filter(|elf| elf.contains(item)).count() == 3) + .copied() + .next() + .unwrap(); p2_priority += priority(badge); elves.clear(); i = 0;