make clippy happy
This commit is contained in:
parent
8896610dac
commit
61798c7ac4
7 changed files with 26 additions and 37 deletions
|
|
@ -5,7 +5,7 @@ pub struct Day01;
|
|||
|
||||
impl Solution for Day01 {
|
||||
fn part_1(&self, input: &str) -> Answer {
|
||||
let words: Vec<&str> = input.split("\n")
|
||||
let words: Vec<&str> = input.split('\n')
|
||||
.collect();
|
||||
|
||||
let mut sum: u64 = 0;
|
||||
|
|
@ -14,9 +14,9 @@ impl Solution for Day01 {
|
|||
let mut first: Option<u64> = None;
|
||||
let mut last: Option<u64> = None;
|
||||
for char in word.chars() {
|
||||
if char.is_digit(10) {
|
||||
if char.is_ascii_digit() {
|
||||
last = Some(char.to_digit(10).unwrap().into());
|
||||
if first == None {
|
||||
if first.is_none() {
|
||||
first = Some(char.to_digit(10).unwrap().into());
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ impl Solution for Day01 {
|
|||
}
|
||||
|
||||
fn part_2(&self, input: &str) -> Answer {
|
||||
let words: Vec<&str> = input.split("\n")
|
||||
let words: Vec<&str> = input.split('\n')
|
||||
.collect();
|
||||
|
||||
let first = Regex::new(
|
||||
|
|
@ -40,7 +40,7 @@ impl Solution for Day01 {
|
|||
).unwrap();
|
||||
|
||||
Answer::from(words.iter()
|
||||
.map(|word| {10 * matches(&first.captures(&word).unwrap()) + matches(&last.captures(&word).unwrap())})
|
||||
.map(|word| {10 * matches(&first.captures(&word).unwrap()) + matches(&last.captures(word).unwrap())})
|
||||
.collect::<Vec<_>>()
|
||||
.iter()
|
||||
.sum::<u64>())
|
||||
|
|
@ -49,10 +49,7 @@ impl Solution for Day01 {
|
|||
|
||||
fn matches(cap: ®ex::Captures) -> u64 {
|
||||
for i in 1..10 {
|
||||
match cap.get(i) {
|
||||
Some(_) => return i as u64,
|
||||
None => (),
|
||||
};
|
||||
if cap.get(i).is_some() { return i as u64 };
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ impl Solution for Day02 {
|
|||
}
|
||||
|
||||
fn part_2(&self, input: &str) -> Answer {
|
||||
let games: Vec<&str> = input.split("\n")
|
||||
let games: Vec<&str> = input.split('\n')
|
||||
.collect();
|
||||
|
||||
let re = Regex::new(r"(\d+) (\w+)").unwrap();
|
||||
|
||||
let mut sum: u64 = 0;
|
||||
|
||||
for (i, game) in games.iter().enumerate() {
|
||||
for (_, game) in games.iter().enumerate() {
|
||||
let mut min_red: u64 = 0;
|
||||
let mut min_blue: u64 = 0;
|
||||
let mut min_green: u64 = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ pub struct Day03;
|
|||
|
||||
impl Solution for Day03 {
|
||||
fn part_1(&self, input: &str) -> Answer {
|
||||
let lines: Vec<&str> = input.split("\n").collect();
|
||||
let lines: Vec<&str> = input.split('\n').collect();
|
||||
|
||||
let mut out: u64 = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ impl Solution for Day05 {
|
|||
let blocks: Vec<&str> = input.split("\n\n")
|
||||
.collect();
|
||||
|
||||
let mut seeds: Vec<SeedRange> = blocks[0].split(" ")
|
||||
let mut seeds: Vec<SeedRange> = blocks[0].split(' ')
|
||||
.skip(1)
|
||||
.collect::<Vec<&str>>()
|
||||
.chunks(2)
|
||||
|
|
@ -53,9 +53,9 @@ impl Solution for Day05 {
|
|||
let rule_blocks: Vec<Vec<Rule>> = blocks.iter()
|
||||
.skip(1)
|
||||
.map(
|
||||
|block| block.split("\n").skip(1).map(
|
||||
|block| block.split('\n').skip(1).map(
|
||||
|line| {
|
||||
let l: Vec<&str> = line.split(" ").collect();
|
||||
let l: Vec<&str> = line.split(' ').collect();
|
||||
Rule::from_rules(l[0].parse::<i64>().unwrap(), l[1].parse::<i64>().unwrap(), l[2].parse::<i64>().unwrap())
|
||||
}
|
||||
).collect()
|
||||
|
|
@ -138,7 +138,7 @@ impl Rule {
|
|||
}
|
||||
|
||||
fn from_rules(dest: i64, source: i64, range: i64) -> Rule {
|
||||
Rule {start: source, end: source + range - 1, offset: (dest - source) as i64}
|
||||
Rule {start: source, end: source + range - 1, offset: (dest - source)}
|
||||
}
|
||||
|
||||
fn apply(&self, seeds: &SeedRange) -> Option<(Option<SeedRange>, SeedRange, Option<SeedRange>)> {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub struct Day06;
|
|||
|
||||
impl Solution for Day06 {
|
||||
fn part_1(&self, input: &str) -> Answer {
|
||||
let data: Vec<&str> = input.split("\n").collect();
|
||||
let data: Vec<&str> = input.split('\n').collect();
|
||||
let times: Vec<u64> = data[0].split_whitespace().skip(1).map(|x| x.parse::<u64>().unwrap()).collect();
|
||||
let dists: Vec<u64> = data[1].split_whitespace().skip(1).map(|x| x.parse::<u64>().unwrap()).collect();
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ impl Solution for Day06 {
|
|||
}
|
||||
|
||||
fn part_2(&self, input: &str) -> Answer {
|
||||
let data: Vec<&str> = input.split("\n").collect();
|
||||
let data: Vec<&str> = input.split('\n').collect();
|
||||
let time: u64 = data[0].split_whitespace().skip(1).collect::<Vec<&str>>().join("").parse::<u64>().unwrap();
|
||||
let dist: u64 = data[1].split_whitespace().skip(1).collect::<Vec<&str>>().join("").parse::<u64>().unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -103,20 +103,14 @@ fn compare2(hand1: &(&str, u64), hand2: &(&str, u64)) -> Ordering {
|
|||
let val = o[&'J'];
|
||||
o.remove(&'J');
|
||||
let max_key = o.iter().max_by(|a, b| a.1.cmp(&b.1)).unwrap_or((&'A', &0)).0;
|
||||
o.insert(*max_key, match o.get(&max_key) {
|
||||
Some(x) => x,
|
||||
None => &0
|
||||
} + val);
|
||||
o.insert(*max_key, o.get(max_key).unwrap_or(&0) + val);
|
||||
}
|
||||
|
||||
if s.contains_key(&'J') {
|
||||
let val = s[&'J'];
|
||||
s.remove(&'J');
|
||||
let max_key = s.iter().max_by(|a, b| a.1.cmp(&b.1)).unwrap_or((&'A', &0)).0;
|
||||
s.insert(*max_key, match s.get(&max_key) {
|
||||
Some(x) => x,
|
||||
None => &0
|
||||
} + val);
|
||||
s.insert(*max_key, s.get(max_key).unwrap_or(&0) + val);
|
||||
}
|
||||
|
||||
if ( s.keys().count() < o.keys().count() ) |
|
||||
|
|
@ -124,7 +118,7 @@ fn compare2(hand1: &(&str, u64), hand2: &(&str, u64)) -> Ordering {
|
|||
else if ( s.keys().count() > o.keys().count() ) |
|
||||
( s.values().max() < o.values().max() ) { return Ordering::Less }
|
||||
|
||||
let ordering = vec!['A', 'K', 'Q', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'J'];
|
||||
let ordering = ['A', 'K', 'Q', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'J'];
|
||||
|
||||
for (i, j) in zip(hand1.0.chars(), hand2.0.chars()) {
|
||||
if ordering.iter().position(|&x| x==i) < ordering.iter().position(|&x| x==j) {
|
||||
|
|
@ -134,5 +128,5 @@ fn compare2(hand1: &(&str, u64), hand2: &(&str, u64)) -> Ordering {
|
|||
}
|
||||
}
|
||||
|
||||
return Ordering::Equal
|
||||
Ordering::Equal
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ impl Solution for Day08 {
|
|||
let directions: HashMap<&str, (&str, &str)> = input.split_once("\n\n")
|
||||
.unwrap()
|
||||
.1
|
||||
.split("\n")
|
||||
.split('\n')
|
||||
.map(|line| {
|
||||
let caps = re.captures(line).unwrap();
|
||||
(caps.get(1).unwrap().as_str(), (caps.get(2).unwrap().as_str(), caps.get(3).unwrap().as_str()))
|
||||
|
|
@ -44,7 +44,7 @@ impl Solution for Day08 {
|
|||
let directions: HashMap<&str, (&str, &str)> = input.split_once("\n\n")
|
||||
.unwrap()
|
||||
.1
|
||||
.split("\n")
|
||||
.split('\n')
|
||||
.map(|line| {
|
||||
let caps = re.captures(line).unwrap();
|
||||
(caps.get(1).unwrap().as_str(), (caps.get(2).unwrap().as_str(), caps.get(3).unwrap().as_str()))
|
||||
|
|
@ -52,7 +52,7 @@ impl Solution for Day08 {
|
|||
.collect::<HashMap<&str, (&str, &str)>>();
|
||||
|
||||
let mut curr: Vec<&str> = directions.keys()
|
||||
.filter_map(|x| if x.chars().last() == Some('A') { Some(*x) } else { None })
|
||||
.filter_map(|x| if x.ends_with('A') { Some(*x) } else { None })
|
||||
.collect();
|
||||
|
||||
let mut steps: u64 = 0;
|
||||
|
|
@ -70,12 +70,12 @@ impl Solution for Day08 {
|
|||
.collect();
|
||||
|
||||
for i in 0..curr.len() {
|
||||
if (period[i] == None && curr[i].chars().last() == Some('Z') ) {
|
||||
if (period[i].is_none() && curr[i].ends_with('Z') ) {
|
||||
period[i] = Some(steps);
|
||||
}
|
||||
}
|
||||
|
||||
if period.iter().all(|x| *x != None) {
|
||||
if period.iter().all(|x| x.is_some()) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -104,12 +104,10 @@ fn gcd(mut n: u64, mut m: u64) -> u64 {
|
|||
// the smaller number
|
||||
if m < n {
|
||||
// initialize a temp variable
|
||||
let temp = m;
|
||||
m = n;
|
||||
n = temp;
|
||||
std::mem::swap(&mut m, &mut n);
|
||||
}
|
||||
// Get the divisor
|
||||
m = m % n;
|
||||
m %= n;
|
||||
}
|
||||
// return n aka the greatest common denominator
|
||||
n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue