Clean up parsing
This commit is contained in:
parent
830c450973
commit
8adfd753cb
@ -7,22 +7,26 @@ struct Robot {
|
|||||||
velocity: IVec2,
|
velocity: IVec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
fn parse(input: &str) -> Vec<Robot> {
|
fn parse(input: &str) -> Vec<Robot> {
|
||||||
let re = Regex::new(r"-?\d+").unwrap();
|
let re = Regex::new(r"-?\d+").unwrap();
|
||||||
input.lines().map(|l| {
|
input
|
||||||
let mut captures = re.captures_iter(l);
|
.lines()
|
||||||
|
.map(|l| {
|
||||||
|
let &[px, py, vx, vy] = re
|
||||||
|
.captures_iter(l)
|
||||||
|
.take(4)
|
||||||
|
.map(|c| c.get(0).unwrap().as_str().parse().unwrap())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.as_slice()
|
||||||
|
else {
|
||||||
|
panic!()
|
||||||
|
};
|
||||||
Robot {
|
Robot {
|
||||||
position: IVec2 {
|
position: IVec2 { x: px, y: py },
|
||||||
x: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(),
|
velocity: IVec2 { x: vx, y: vy },
|
||||||
y: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(),
|
|
||||||
},
|
|
||||||
velocity: IVec2 {
|
|
||||||
x: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(),
|
|
||||||
y: captures.next().unwrap().get(0).unwrap().as_str().parse().unwrap(),
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}).collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pos_after_steps(robot: &Robot, steps: &i32, dimensions: &IVec2) -> IVec2 {
|
fn get_pos_after_steps(robot: &Robot, steps: &i32, dimensions: &IVec2) -> IVec2 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user