mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Reuse input helper.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::io::Read;
|
||||
|
||||
use common::Solution;
|
||||
use common::read_single_input;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Day08 {}
|
||||
@@ -58,8 +59,7 @@ impl Day08 {
|
||||
|
||||
impl Solution for Day08 {
|
||||
fn part1(&mut self, input: &mut Read) -> String {
|
||||
let mut data = String::new();
|
||||
input.read_to_string(&mut data).unwrap();
|
||||
let data: String = read_single_input(input);
|
||||
|
||||
let data: Vec<usize> = data.trim().split(" ").map(|x| x.parse().unwrap()).collect();
|
||||
let (result, _) = total1(&data);
|
||||
@@ -68,8 +68,7 @@ impl Solution for Day08 {
|
||||
}
|
||||
|
||||
fn part2(&mut self, input: &mut Read) -> String {
|
||||
let mut data = String::new();
|
||||
input.read_to_string(&mut data).unwrap();
|
||||
let data: String = read_single_input(input);
|
||||
|
||||
let data: Vec<usize> = data.trim().split(" ").map(|x| x.parse().unwrap()).collect();
|
||||
let (result, _) = total2(&data);
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::i32;
|
||||
use std::io::Read;
|
||||
|
||||
use common::Solution;
|
||||
use common::read_single_input;
|
||||
|
||||
fn power_at(serial: i32, (x, y): (i32, i32)) -> i32 {
|
||||
let rack_id = x + 10;
|
||||
@@ -23,12 +24,6 @@ impl Day11 {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_serial(&self, input: &mut Read) -> i32 {
|
||||
let mut data = String::new();
|
||||
input.read_to_string(&mut data).unwrap();
|
||||
data.trim().parse().unwrap()
|
||||
}
|
||||
|
||||
fn compute_summed_area(&mut self, serial: i32) {
|
||||
self.power_grid[0][0] = power_at(serial, (1, 1));
|
||||
for x in 1..300 {
|
||||
@@ -93,7 +88,7 @@ impl Day11 {
|
||||
|
||||
impl Solution for Day11 {
|
||||
fn part1(&mut self, input: &mut Read) -> String {
|
||||
let serial = self.read_serial(input);
|
||||
let serial = read_single_input(input);
|
||||
self.compute_summed_area(serial);
|
||||
let (x, y, _) = self.best(3);
|
||||
|
||||
@@ -101,7 +96,7 @@ impl Solution for Day11 {
|
||||
}
|
||||
|
||||
fn part2(&mut self, input: &mut Read) -> String {
|
||||
let serial = self.read_serial(input);
|
||||
let serial = read_single_input(input);
|
||||
self.compute_summed_area(serial);
|
||||
let mut best_result = 0;
|
||||
let mut best_option = None;
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use common::Solution;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user