fn course_path(path: &str) -> u32 {
    let commands = parse(path);
    let mut horizontal = 0;
    let mut depth = 0;

    for command in commands {
        match command.direction.as_str() {
            "forward" => horizontal += command.position,
            "down" => depth += command.position,
            "up" => depth -= command.position,
            _ => (),
        }
    }

    return horizontal * depth;
}
// Part One: Calculates the horizontal position and depth of the course
Part One: Calculates the horizontal position and depth of the course
Part One : Calculates the horizontal position and depth of the course
fn course_path(path: &str) -> u32 {
    let commands = parse(path);
    let mut horizontal = 0;
    let mut depth = 0;
    for command in commands {
        match command.direction.as_str() {
            "forward" => horizontal += command.position,
            "down" => depth += command.position,
            "up" => depth -= command.position,
            _ => (),
        }
    }
    return horizontal * depth;
}
fn course_path ( path : & str ) -> u32 { let commands = parse ( path ) ; let mut horizontal = 0 ; let mut depth = 0 ; for command in commands { match command . direction . as_str ( ) { " " => horizontal += command . position , " " => depth += command . position , " " => depth -= command . position , _ => ( ) , } } return horizontal * depth ; }
Part One: Calculates the horizontal position and depth of the course
Part One : Calculates the horizontal position and depth of the course
path
&str