implements new fn

This commit is contained in:
Victor Martinez Montane 2021-12-02 23:32:09 +01:00
parent c3baa58cf6
commit 1f3a5ac38e
2 changed files with 21 additions and 9 deletions

View file

@ -9,12 +9,8 @@ use std::path::Path;
static INPUT_PATH: &str = "input.txt"; static INPUT_PATH: &str = "input.txt";
fn main() -> Result<()> { fn main() -> Result<()> {
let submarine_v1 = SubmarineV1 { xcord: 0, depth: 0 }; let submarine_v1 = SubmarineV1::new();
let submarine_v2 = SubmarineV2 { let submarine_v2 = SubmarineV2::new();
xcord: 0,
depth: 0,
aim: 0,
};
let commands = read_commands(INPUT_PATH)?; let commands = read_commands(INPUT_PATH)?;
let submarine_v1 = apply_commands(submarine_v1, &commands); let submarine_v1 = apply_commands(submarine_v1, &commands);

View file

@ -15,6 +15,12 @@ pub struct SubmarineV1 {
pub depth: i32, pub depth: i32,
} }
impl SubmarineV1 {
pub fn new() -> Self {
SubmarineV1 { xcord: 0, depth: 0 }
}
}
impl Submarine for SubmarineV1 { impl Submarine for SubmarineV1 {
fn forward(self, unit: i32) -> Self { fn forward(self, unit: i32) -> Self {
SubmarineV1 { SubmarineV1 {
@ -48,9 +54,19 @@ impl Submarine for SubmarineV1 {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct SubmarineV2 { pub struct SubmarineV2 {
pub xcord: i32, xcord: i32,
pub depth: i32, depth: i32,
pub aim: i32, aim: i32,
}
impl SubmarineV2 {
pub fn new() -> Self {
Self {
xcord: 0,
depth: 0,
aim: 0,
}
}
} }
impl Submarine for SubmarineV2 { impl Submarine for SubmarineV2 {