From f1a1e672ab43adb5496b5e8b0beca801d5315a89 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 5 Dec 2022 19:56:31 +0100 Subject: [PATCH] Group imports --- src/common.rs | 4 +--- src/day03.rs | 5 +---- src/day04.rs | 2 +- src/day06.rs | 3 +-- src/day07.rs | 6 ++++-- src/day11.rs | 1 + src/day12.rs | 3 +-- src/day13.rs | 7 ++++--- src/day15.rs | 5 ++--- src/day17.rs | 8 ++++---- src/intcode.rs | 4 ++-- 11 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/common.rs b/src/common.rs index f22fbfd..ab6774b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,4 @@ -use std::fs; -use std::path::Path; -use std::str::FromStr; +use std::{fs, path::Path, str::FromStr}; pub fn read_list_of_numbers(file: P, sep: &str) -> Vec where diff --git a/src/day03.rs b/src/day03.rs index 808f6f9..cb50f8a 100644 --- a/src/day03.rs +++ b/src/day03.rs @@ -1,7 +1,4 @@ -use std::iter::Iterator; -use std::iter::FromIterator; -use std::collections::HashSet; -use std::collections::HashMap; +use std::{collections::{HashMap, HashSet}, iter::{Iterator, FromIterator}}; pub fn split_movements(movements: &str) -> Vec<&str> { movements.split(',').collect() diff --git a/src/day04.rs b/src/day04.rs index 53a8c24..5f66df4 100644 --- a/src/day04.rs +++ b/src/day04.rs @@ -58,7 +58,7 @@ fn nb_passwords(min: i32, max: i32, valid_password: &dyn Fn(&Digits) -> bool) -> fn set_range(from: usize, to: usize, value: u8, digits: &mut Digits) { for d in &mut digits[from .. to] { *d = value; } - }; + } for i in (1 .. l).rev() { if digits[i - 1] < digits[i] { diff --git a/src/day06.rs b/src/day06.rs index c0d4ae0..1ff649d 100644 --- a/src/day06.rs +++ b/src/day06.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; -use std::cmp; +use std::{cmp, collections::HashMap}; // All planets indexing their parent (planet -> parent). type Orbits = HashMap; diff --git a/src/day07.rs b/src/day07.rs index 61a370a..1ab98f7 100644 --- a/src/day07.rs +++ b/src/day07.rs @@ -1,8 +1,10 @@ -use super::intcode; +use std::sync::{Arc, Barrier, mpsc::{self, Sender, Receiver}, atomic::{AtomicI64, Ordering}}; + use itertools::Itertools; -use std::sync::{ Arc, Barrier, mpsc::{ self, Sender, Receiver }, atomic::{ AtomicI64, Ordering } }; use threadpool::ThreadPool; +use super::intcode; + fn last_thruster_signal(code: &[i64], phase_setting: &[i64]) -> i64 { phase_setting.iter().fold(0, |last_output, input| intcode::execute_op_code(&code, &[*input, last_output])[0]) } diff --git a/src/day11.rs b/src/day11.rs index 2320722..8847bb1 100644 --- a/src/day11.rs +++ b/src/day11.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; + use super::intcode; enum NextCommand { diff --git a/src/day12.rs b/src/day12.rs index fbfe5de..db95447 100644 --- a/src/day12.rs +++ b/src/day12.rs @@ -1,5 +1,4 @@ -use std::ops::AddAssign; -use std::cmp::Ordering; +use std::{cmp::Ordering, ops::AddAssign}; #[derive(Debug, Copy, Clone)] pub struct Vector3D { diff --git a/src/day13.rs b/src/day13.rs index edf2132..286791b 100644 --- a/src/day13.rs +++ b/src/day13.rs @@ -1,9 +1,10 @@ -use super::intcode; -use std::cmp::Ordering; -use std::convert::TryFrom; +use std::{cmp::Ordering, convert::TryFrom}; + use itertools::Itertools; use num_enum::TryFromPrimitive; +use super::intcode; + // Not neccesary, to try to parse enum in Rust. #[derive(Debug, Eq, PartialEq, TryFromPrimitive)] #[repr(u8)] diff --git a/src/day15.rs b/src/day15.rs index e6286e2..2af8e3c 100644 --- a/src/day15.rs +++ b/src/day15.rs @@ -1,7 +1,6 @@ +use std::{collections::{HashMap, HashSet}, iter::FromIterator}; + use super::intcode; -use std::iter::FromIterator; -use std::collections::HashMap; -use std::collections::HashSet; #[derive(Debug, Eq, PartialEq, Copy, Clone)] enum LocationState { diff --git a/src/day17.rs b/src/day17.rs index 75ed1a9..c3c3917 100644 --- a/src/day17.rs +++ b/src/day17.rs @@ -1,8 +1,8 @@ -use super::intcode; +use std::{collections::HashSet, convert::TryFrom, ops::Range}; + use itertools::Itertools; -use std::collections::HashSet; -use std::convert::TryFrom; -use std::ops::Range; + +use super::intcode; #[derive(PartialEq, Eq, Copy, Clone, Debug)] enum Direction { Up, Left, Down, Right } diff --git a/src/intcode.rs b/src/intcode.rs index ff3e34b..fee58ca 100644 --- a/src/intcode.rs +++ b/src/intcode.rs @@ -73,7 +73,7 @@ pub fn execute_op_code_with_custom_io(code: &[i64], io: &mut dyn IO) { Mode::Immediate => code[position], Mode::Relative => if (code[position] + relative_base) as usize >= code.len() { 0 } else { code[(code[position] + relative_base) as usize] } } - }; + } fn write(position: usize, value: i64, code: &mut Vec, mode: Mode, relative_base: i64) { let ref_position = @@ -97,7 +97,7 @@ pub fn execute_op_code_with_custom_io(code: &[i64], io: &mut dyn IO) { } else { cursor + 3 } - }; + } loop { if io.halt() { break; } -- 2.45.2