mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Replace format("{}") with .to_string() where possible.
This commit is contained in:
@@ -21,7 +21,7 @@ impl common::Solution for Day01 {
|
|||||||
.map(|x| x.unwrap().parse::<i32>().unwrap())
|
.map(|x| x.unwrap().parse::<i32>().unwrap())
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
format!("{}", sum)
|
sum.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut io::Read) -> String {
|
fn part2(&mut self, input: &mut io::Read) -> String {
|
||||||
@@ -37,7 +37,7 @@ impl common::Solution for Day01 {
|
|||||||
for amount in &nums {
|
for amount in &nums {
|
||||||
sum += amount;
|
sum += amount;
|
||||||
if freqs.contains(&sum) {
|
if freqs.contains(&sum) {
|
||||||
return format!("{}", sum);
|
return sum.to_string();
|
||||||
} else {
|
} else {
|
||||||
freqs.insert(sum);
|
freqs.insert(sum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl common::Solution for Day02 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return format!("{}", twos * threes);
|
(twos * threes).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut io::Read) -> String {
|
fn part2(&mut self, input: &mut io::Read) -> String {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ impl common::Solution for Day03 {
|
|||||||
.filter(|&&x| x > 1)
|
.filter(|&&x| x > 1)
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
format!("{}", multi_claim)
|
multi_claim.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut io::Read) -> String {
|
fn part2(&mut self, input: &mut io::Read) -> String {
|
||||||
@@ -89,7 +89,7 @@ impl common::Solution for Day03 {
|
|||||||
.position(|x| x.range().all(|x| claims[&x] == 1))
|
.position(|x| x.range().all(|x| claims[&x] == 1))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
format!("{}", uncontested + 1)
|
(uncontested + 1).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ impl Day04 {
|
|||||||
let best_minute = sleepers[best_sleeper].iter().enumerate()
|
let best_minute = sleepers[best_sleeper].iter().enumerate()
|
||||||
.max_by(|&(_, a), &(_, b)| a.cmp(b)).unwrap().0;
|
.max_by(|&(_, a), &(_, b)| a.cmp(b)).unwrap().0;
|
||||||
|
|
||||||
format!("{}", best_sleeper * (best_minute as usize))
|
(best_sleeper * (best_minute as usize)).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ impl common::Solution for Day05 {
|
|||||||
input.read_to_end(&mut data).expect("Can't read input!");
|
input.read_to_end(&mut data).expect("Can't read input!");
|
||||||
common::trim_back(&mut data);
|
common::trim_back(&mut data);
|
||||||
|
|
||||||
format!("{}", Day05::reduce(data))
|
Day05::reduce(data).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -46,7 +46,7 @@ impl common::Solution for Day05 {
|
|||||||
.map(Day05::reduce)
|
.map(Day05::reduce)
|
||||||
.min().unwrap();
|
.min().unwrap();
|
||||||
|
|
||||||
format!("{}", min_len)
|
min_len.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ impl Solution for Day06 {
|
|||||||
.filter_map(claim_filter)
|
.filter_map(claim_filter)
|
||||||
.filter(|x| !infinite.contains(x)).grouping_count();
|
.filter(|x| !infinite.contains(x)).grouping_count();
|
||||||
|
|
||||||
format!("{}", counts.values().max().unwrap())
|
counts.values().max().unwrap().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
format!("{}", self.part2_with_limit(input, 10_000))
|
self.part2_with_limit(input, 10_000).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ impl Solution for Day07 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
format!("{}", self.part2_parametrized(input, 60, 5))
|
self.part2_parametrized(input, 60, 5).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ impl Solution for Day08 {
|
|||||||
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();
|
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();
|
||||||
let (result, _) = total1(&data);
|
let (result, _) = total1(&data);
|
||||||
|
|
||||||
format!("{}", result)
|
result.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -73,7 +73,7 @@ impl Solution for Day08 {
|
|||||||
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();
|
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();
|
||||||
let (result, _) = total2(&data);
|
let (result, _) = total2(&data);
|
||||||
|
|
||||||
format!("{}", result)
|
result.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,13 +55,13 @@ impl Solution for Day09 {
|
|||||||
fn part1(&mut self, input: &mut Read) -> String {
|
fn part1(&mut self, input: &mut Read) -> String {
|
||||||
let (elves, marbles) = Day09::read_input(input);
|
let (elves, marbles) = Day09::read_input(input);
|
||||||
|
|
||||||
format!("{}", winning_marbles(elves, marbles))
|
winning_marbles(elves, marbles).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
let (elves, marbles) = Day09::read_input(input);
|
let (elves, marbles) = Day09::read_input(input);
|
||||||
|
|
||||||
format!("{}", winning_marbles(elves, marbles * 100))
|
winning_marbles(elves, marbles * 100).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ impl Solution for Day10 {
|
|||||||
self.run(1);
|
self.run(1);
|
||||||
height = self.height();
|
height = self.height();
|
||||||
}
|
}
|
||||||
format!("{}", steps - 1)
|
(steps - 1).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ impl Solution for Day12 {
|
|||||||
let mut state = self.read_input(input);
|
let mut state = self.read_input(input);
|
||||||
state = self.simulate_n(state, 20);
|
state = self.simulate_n(state, 20);
|
||||||
|
|
||||||
format!("{}", self.sum(&state))
|
self.sum(&state).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl Solution for Day14 {
|
|||||||
input.read_to_string(&mut buf).unwrap();
|
input.read_to_string(&mut buf).unwrap();
|
||||||
|
|
||||||
let input = buf.trim().parse().unwrap();
|
let input = buf.trim().parse().unwrap();
|
||||||
format!("{}", find_first(input, buf.trim().len()))
|
find_first(input, buf.trim().len()).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ impl Day15 {
|
|||||||
fn return_score(&self, rounds: usize) -> String {
|
fn return_score(&self, rounds: usize) -> String {
|
||||||
let result: usize = rounds * self.units.iter().map(|x| x.hp as usize)
|
let result: usize = rounds * self.units.iter().map(|x| x.hp as usize)
|
||||||
.sum::<usize>();
|
.sum::<usize>();
|
||||||
format!("{}", result)
|
result.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_elf_power(&mut self, power: u8) {
|
fn set_elf_power(&mut self, power: u8) {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ impl Solution for Day16 {
|
|||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format!("{}", counter)
|
counter.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -145,7 +145,7 @@ impl Solution for Day16 {
|
|||||||
cpu.execute(mapping[op[0] as usize], &op[1..4]).unwrap();
|
cpu.execute(mapping[op[0] as usize], &op[1..4]).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
format!("{}", cpu.registers[0])
|
cpu.registers[0].to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ impl Solution for Day17 {
|
|||||||
|
|
||||||
let result = self.contained.len()
|
let result = self.contained.len()
|
||||||
+ self.flowing.len() - self.ymin;
|
+ self.flowing.len() - self.ymin;
|
||||||
format!("{}", result)
|
result.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -129,7 +129,7 @@ impl Solution for Day17 {
|
|||||||
|
|
||||||
self.descend((500, 0));
|
self.descend((500, 0));
|
||||||
|
|
||||||
format!("{}", self.contained.len())
|
self.contained.len().to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ impl Day18 {
|
|||||||
.flat_map(|x| x.iter())
|
.flat_map(|x| x.iter())
|
||||||
.cloned().grouping_count();
|
.cloned().grouping_count();
|
||||||
|
|
||||||
format!("{}", result[&Tile::Tree] * result[&Tile::Lumber])
|
(result[&Tile::Tree] * result[&Tile::Lumber]).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl Solution for Day19 {
|
|||||||
cpu.registers[self.ip] += 1;
|
cpu.registers[self.ip] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
format!("{}", cpu.registers[0])
|
cpu.registers[0].to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -73,7 +73,7 @@ impl Solution for Day19 {
|
|||||||
cpu.registers[self.ip] += 1;
|
cpu.registers[self.ip] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
format!("{}", cpu.registers[0])
|
cpu.registers[0].to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ impl Solution for Day20 {
|
|||||||
let pos = (0, 0);
|
let pos = (0, 0);
|
||||||
|
|
||||||
self.follow_directions(&[pos], &data[1..]);
|
self.follow_directions(&[pos], &data[1..]);
|
||||||
format!("{}", self.distances().values().max().unwrap())
|
self.distances().values().max().unwrap().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -147,7 +147,7 @@ impl Solution for Day20 {
|
|||||||
let pos = (0, 0);
|
let pos = (0, 0);
|
||||||
|
|
||||||
self.follow_directions(&[pos], &data[1..]);
|
self.follow_directions(&[pos], &data[1..]);
|
||||||
format!("{}", self.distances().values().filter(|&&x| x >= 1000).count())
|
self.distances().values().filter(|&&x| x >= 1000).count().to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,17 +52,17 @@ impl Day21 {
|
|||||||
|
|
||||||
impl Solution for Day21 {
|
impl Solution for Day21 {
|
||||||
fn part1(&mut self, _input: &mut Read) -> String {
|
fn part1(&mut self, _input: &mut Read) -> String {
|
||||||
format!("{}", ValidInputs::new(0).next().unwrap())
|
ValidInputs::new(0).next().unwrap().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, _input: &mut Read) -> String {
|
fn part2(&mut self, _input: &mut Read) -> String {
|
||||||
let inputs = ValidInputs::new(0);
|
let inputs = ValidInputs::new(0);
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
let mut last = None;
|
let mut last: Option<i64> = None;
|
||||||
|
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
if seen.contains(&input) {
|
if seen.contains(&input) {
|
||||||
return format!("{}", last.unwrap());
|
return last.unwrap().to_string();
|
||||||
} else {
|
} else {
|
||||||
last = Some(input);
|
last = Some(input);
|
||||||
seen.insert(input);
|
seen.insert(input);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ impl Solution for Day22 {
|
|||||||
|
|
||||||
let result: usize = table.iter().flat_map(|x| x.iter())
|
let result: usize = table.iter().flat_map(|x| x.iter())
|
||||||
.sum();
|
.sum();
|
||||||
format!("{}", result)
|
result.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: &mut Read) -> String {
|
fn part2(&mut self, input: &mut Read) -> String {
|
||||||
@@ -115,7 +115,7 @@ impl Solution for Day22 {
|
|||||||
}
|
}
|
||||||
visited.insert(state);
|
visited.insert(state);
|
||||||
if state == target_state {
|
if state == target_state {
|
||||||
return format!("{}", dist);
|
return dist.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
let (x, y) = state.pos;
|
let (x, y) = state.pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user