Replace format("{}") with .to_string() where possible.

This commit is contained in:
2018-12-22 10:06:36 +01:00
parent 3b825ac933
commit 2f0c8ef2d4
20 changed files with 33 additions and 33 deletions

View File

@@ -21,7 +21,7 @@ impl common::Solution for Day01 {
.map(|x| x.unwrap().parse::<i32>().unwrap())
.sum();
format!("{}", sum)
sum.to_string()
}
fn part2(&mut self, input: &mut io::Read) -> String {
@@ -37,7 +37,7 @@ impl common::Solution for Day01 {
for amount in &nums {
sum += amount;
if freqs.contains(&sum) {
return format!("{}", sum);
return sum.to_string();
} else {
freqs.insert(sum);
}

View File

@@ -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 {

View File

@@ -78,7 +78,7 @@ impl common::Solution for Day03 {
.filter(|&&x| x > 1)
.count();
format!("{}", multi_claim)
multi_claim.to_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))
.unwrap();
format!("{}", uncontested + 1)
(uncontested + 1).to_string()
}
}

View File

@@ -92,7 +92,7 @@ impl Day04 {
let best_minute = sleepers[best_sleeper].iter().enumerate()
.max_by(|&(_, a), &(_, b)| a.cmp(b)).unwrap().0;
format!("{}", best_sleeper * (best_minute as usize))
(best_sleeper * (best_minute as usize)).to_string()
}
}

View File

@@ -34,7 +34,7 @@ impl common::Solution for Day05 {
input.read_to_end(&mut data).expect("Can't read input!");
common::trim_back(&mut data);
format!("{}", Day05::reduce(data))
Day05::reduce(data).to_string()
}
fn part2(&mut self, input: &mut Read) -> String {
@@ -46,7 +46,7 @@ impl common::Solution for Day05 {
.map(Day05::reduce)
.min().unwrap();
format!("{}", min_len)
min_len.to_string()
}
}

View File

@@ -111,11 +111,11 @@ impl Solution for Day06 {
.filter_map(claim_filter)
.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 {
format!("{}", self.part2_with_limit(input, 10_000))
self.part2_with_limit(input, 10_000).to_string()
}
}

View File

@@ -128,7 +128,7 @@ impl Solution for Day07 {
}
fn part2(&mut self, input: &mut Read) -> String {
format!("{}", self.part2_parametrized(input, 60, 5))
self.part2_parametrized(input, 60, 5).to_string()
}
}

View File

@@ -64,7 +64,7 @@ impl Solution for Day08 {
let data: Vec<usize> = data.trim().split(' ').map(|x| x.parse().unwrap()).collect();
let (result, _) = total1(&data);
format!("{}", result)
result.to_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 (result, _) = total2(&data);
format!("{}", result)
result.to_string()
}
}

View File

@@ -55,13 +55,13 @@ impl Solution for Day09 {
fn part1(&mut self, input: &mut Read) -> String {
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 {
let (elves, marbles) = Day09::read_input(input);
format!("{}", winning_marbles(elves, marbles * 100))
winning_marbles(elves, marbles * 100).to_string()
}
}

View File

@@ -117,7 +117,7 @@ impl Solution for Day10 {
self.run(1);
height = self.height();
}
format!("{}", steps - 1)
(steps - 1).to_string()
}
}

View File

@@ -110,7 +110,7 @@ impl Solution for Day12 {
let mut state = self.read_input(input);
state = self.simulate_n(state, 20);
format!("{}", self.sum(&state))
self.sum(&state).to_string()
}
fn part2(&mut self, input: &mut Read) -> String {

View File

@@ -87,7 +87,7 @@ impl Solution for Day14 {
input.read_to_string(&mut buf).unwrap();
let input = buf.trim().parse().unwrap();
format!("{}", find_first(input, buf.trim().len()))
find_first(input, buf.trim().len()).to_string()
}
}

View File

@@ -194,7 +194,7 @@ impl Day15 {
fn return_score(&self, rounds: usize) -> String {
let result: usize = rounds * self.units.iter().map(|x| x.hp as usize)
.sum::<usize>();
format!("{}", result)
result.to_string()
}
fn set_elf_power(&mut self, power: u8) {

View File

@@ -126,7 +126,7 @@ impl Solution for Day16 {
counter += 1;
}
}
format!("{}", counter)
counter.to_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();
}
format!("{}", cpu.registers[0])
cpu.registers[0].to_string()
}
}

View File

@@ -121,7 +121,7 @@ impl Solution for Day17 {
let result = self.contained.len()
+ self.flowing.len() - self.ymin;
format!("{}", result)
result.to_string()
}
fn part2(&mut self, input: &mut Read) -> String {
@@ -129,7 +129,7 @@ impl Solution for Day17 {
self.descend((500, 0));
format!("{}", self.contained.len())
self.contained.len().to_string()
}
}

View File

@@ -133,7 +133,7 @@ impl Day18 {
.flat_map(|x| x.iter())
.cloned().grouping_count();
format!("{}", result[&Tile::Tree] * result[&Tile::Lumber])
(result[&Tile::Tree] * result[&Tile::Lumber]).to_string()
}
}

View File

@@ -50,7 +50,7 @@ impl Solution for Day19 {
cpu.registers[self.ip] += 1;
}
format!("{}", cpu.registers[0])
cpu.registers[0].to_string()
}
fn part2(&mut self, input: &mut Read) -> String {
@@ -73,7 +73,7 @@ impl Solution for Day19 {
cpu.registers[self.ip] += 1;
}
format!("{}", cpu.registers[0])
cpu.registers[0].to_string()
}
}

View File

@@ -138,7 +138,7 @@ impl Solution for Day20 {
let pos = (0, 0);
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 {
@@ -147,7 +147,7 @@ impl Solution for Day20 {
let pos = (0, 0);
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()
}
}

View File

@@ -52,17 +52,17 @@ impl Day21 {
impl Solution for Day21 {
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 {
let inputs = ValidInputs::new(0);
let mut seen = HashSet::new();
let mut last = None;
let mut last: Option<i64> = None;
for input in inputs {
if seen.contains(&input) {
return format!("{}", last.unwrap());
return last.unwrap().to_string();
} else {
last = Some(input);
seen.insert(input);

View File

@@ -95,7 +95,7 @@ impl Solution for Day22 {
let result: usize = table.iter().flat_map(|x| x.iter())
.sum();
format!("{}", result)
result.to_string()
}
fn part2(&mut self, input: &mut Read) -> String {
@@ -115,7 +115,7 @@ impl Solution for Day22 {
}
visited.insert(state);
if state == target_state {
return format!("{}", dist);
return dist.to_string();
}
let (x, y) = state.pos;