Remove split char parameter from Point2 and Point3 constructors
This commit is contained in:
+20
-4
@@ -2,8 +2,16 @@
|
||||
pub struct Point2(pub u64, pub u64);
|
||||
|
||||
impl Point2 {
|
||||
pub fn from_line(line: &str, separator: char) -> Self {
|
||||
let p: Vec<u64> = line.split(separator).map(|s| s.parse().unwrap()).collect();
|
||||
const POINT_SPLIT_CHAR: char = ',';
|
||||
|
||||
pub fn from_line(line: &str) -> Self {
|
||||
let p: Vec<u64> = line
|
||||
.split(Self::POINT_SPLIT_CHAR)
|
||||
.map(|s| {
|
||||
s.parse()
|
||||
.expect(&format!("could not create Point2 from line '{line}'"))
|
||||
})
|
||||
.collect();
|
||||
Self(p[0], p[1])
|
||||
}
|
||||
|
||||
@@ -16,8 +24,16 @@ impl Point2 {
|
||||
pub struct Point3(pub u64, pub u64, pub u64);
|
||||
|
||||
impl Point3 {
|
||||
pub fn from_line(line: &str, separator: char) -> Self {
|
||||
let p: Vec<u64> = line.split(separator).map(|s| s.parse().unwrap()).collect();
|
||||
const POINT_SPLIT_CHAR: char = ',';
|
||||
|
||||
pub fn from_line(line: &str) -> Self {
|
||||
let p: Vec<u64> = line
|
||||
.split(Self::POINT_SPLIT_CHAR)
|
||||
.map(|s| {
|
||||
s.parse()
|
||||
.expect(&format!("could not create Point3 from line '{line}'"))
|
||||
})
|
||||
.collect();
|
||||
Self(p[0], p[1], p[2])
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,11 @@ use std::io::BufRead;
|
||||
pub struct MovieTheater {}
|
||||
|
||||
impl MovieTheater {
|
||||
const POINT_SPLIT_CHAR: char = ',';
|
||||
|
||||
// Collects all red tile coordinates.
|
||||
fn red_tiles<R: BufRead>(reader: R) -> Vec<Point2> {
|
||||
let mut red_tiles = Vec::new();
|
||||
for line in reader.lines().map_while(Result::ok) {
|
||||
red_tiles.push(Point2::from_line(&line, Self::POINT_SPLIT_CHAR));
|
||||
red_tiles.push(Point2::from_line(&line));
|
||||
}
|
||||
red_tiles
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@ pub struct Playground {
|
||||
}
|
||||
|
||||
impl Playground {
|
||||
const POINT_SPLIT_CHAR: char = ',';
|
||||
const CIRCUITS_TAKE: usize = 3;
|
||||
|
||||
pub fn new(connections: Option<usize>) -> Playground {
|
||||
Playground {
|
||||
pub fn new(connections: Option<usize>) -> Self {
|
||||
Self {
|
||||
connections: connections.unwrap_or(1000),
|
||||
}
|
||||
}
|
||||
@@ -21,7 +20,7 @@ impl Playground {
|
||||
fn junction_boxes<R: BufRead>(reader: R) -> Vec<Point3> {
|
||||
let mut junction_boxes = Vec::new();
|
||||
for line in reader.lines().map_while(Result::ok) {
|
||||
junction_boxes.push(Point3::from_line(&line, Self::POINT_SPLIT_CHAR));
|
||||
junction_boxes.push(Point3::from_line(&line));
|
||||
}
|
||||
junction_boxes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user