fn exec(v: &Vec<(&str, i32)>) -> (i32, bool) {
    let mut accu = 0_i32;
    let mut visited = HashSet::<usize>::with_capacity(v.len());

    let mut curr_inst = 0_usize;
    loop {
        if visited.contains(&curr_inst) {
            return (accu, false);
        }
        let inst = v[curr_inst];
        visited.insert(curr_inst);

        match inst.0 {
            "nop" => curr_inst += 1,
            "acc" => {
                curr_inst += 1;
                accu += inst.1
            }
            "jmp" => {
                let next_inst = curr_inst as i32 + inst.1;
                curr_inst = next_inst as usize;
            }
            _ => panic!("Unknown instruction: {}", inst.0),
        }

        //println!("Executed: {:?}", inst);
        //println!("accu: {}", accu);
        //println!("next inst: {}", curr_inst);

        if curr_inst == v.len() {
            return (accu, true);
        }
    }
}
// return gives you the value if the accumulator and false if an instruction is repeated or
// value of the accumulator and true if the execution ends at the last instruction.
return gives you the value if the accumulator and false if an instruction is repeated or
value of the accumulator and true if the execution ends at the last instruction.
return gives you the value if the accumulator and false if an instruction is repeated or value of the accumulator and true if the execution ends at the last instruction .
fn exec(v: &Vec<(&str, i32)>) -> (i32, bool) {
    let mut accu = 0_i32;
    let mut visited = HashSet::<usize>::with_capacity(v.len());
    let mut curr_inst = 0_usize;
    loop {
        if visited.contains(&curr_inst) {
            return (accu, false);
        }
        let inst = v[curr_inst];
        visited.insert(curr_inst);
        match inst.0 {
            "nop" => curr_inst += 1,
            "acc" => {
                curr_inst += 1;
                accu += inst.1
            }
            "jmp" => {
                let next_inst = curr_inst as i32 + inst.1;
                curr_inst = next_inst as usize;
            }
            _ => panic!("Unknown instruction: {}", inst.0),
        }
        //println!("Executed: {:?}", inst);
        //println!("accu: {}", accu);
        //println!("next inst: {}", curr_inst);
        if curr_inst == v.len() {
            return (accu, true);
        }
    }
}
fn exec ( v : & Vec < ( & str , i32 ) > ) -> ( i32 , bool ) { let mut accu = 0_i32 ; let mut visited = HashSet :: < usize > :: with_capacity ( v . len ( ) ) ; let mut curr_inst = 0_usize ; loop { if visited . contains ( & curr_inst ) { return ( accu , false ) ; } let inst = v [ curr_inst ] ; visited . insert ( curr_inst ) ; match inst . 0 { " " => curr_inst += 1 , " " => { curr_inst += 1 ; accu += inst . 1 } " " => { let next_inst = curr_inst as i32 + inst . 1 ; curr_inst = next_inst as usize ; } _ => panic ! ( " " inst 0 ) , } //println!("Executed: {:?}", inst); //println!("accu: {}", accu); //println!("next inst: {}", curr_inst); if curr_inst == v . len ( ) { return ( accu , true ) ; } } }
return gives you the value if the accumulator and false if an instruction is repeated or
value of the accumulator and true if the execution ends at the last instruction.
return gives you the value if the accumulator and false if an instruction is repeated or value of the accumulator and true if the execution ends at the last instruction .
v
&Vec<(&str, i32)>
v
&Vec<(&str, i32)>