pub fn run_v2(instructions: &[Instruction]) -> HashMap<u64, u64> {
    // memory map: address -> value
    let mut memory = HashMap::new();

    // current mask
    let mut mask = BitMask { ones: BitMask::ALL, zeros: 0 };

    for instruction in instructions {
        match instruction {
            // update mask or insert value at all relevant addresses
            Instruction::BitMask(new_mask) => mask = *new_mask,
            Instruction::Write((address, value)) => {
                // apply ones to address
                let address = *address | mask.ones;
                // iterate over all combinations of floating bits and add value to memory addresses
                for (mask, none) in BitMaskNones::from(&mask) {
                    memory.insert((address & !mask) | none, *value);
                }
            }
        }
    }

    // return memory
    memory
}
// tag::run_v2[]
/// Solve part 1
///
/// Iterating over all combinations of floating bits is done with my first own Iterator in Rust.
/// See [`BitMaskNones`].
:run_v2[]
Solve part 1

Iterating over all combinations of floating bits is done with my first own Iterator in Rust.
: run_v2 [] Solve part 1 Iterating over all combinations of floating bits is done with my first own Iterator in Rust .
pub fn run_v2(instructions: &[Instruction]) -> HashMap<u64, u64> {
    // memory map: address -> value
    let mut memory = HashMap::new();
    // current mask
    let mut mask = BitMask { ones: BitMask::ALL, zeros: 0 };
    for instruction in instructions {
        match instruction {
            // update mask or insert value at all relevant addresses
            Instruction::BitMask(new_mask) => mask = *new_mask,
            Instruction::Write((address, value)) => {
                // apply ones to address
                let address = *address | mask.ones;
                // iterate over all combinations of floating bits and add value to memory addresses
                for (mask, none) in BitMaskNones::from(&mask) {
                    memory.insert((address & !mask) | none, *value);
                }
            }
        }
    }
    // return memory
    memory
}
pub fn run_v2 ( instructions : & [ Instruction ] ) -> HashMap < u64 , u64 > { // memory map: address -> value let mut memory = HashMap :: new ( ) ; // current mask let mut mask = BitMask { ones : BitMask :: ALL , zeros : 0 } ; for instruction in instructions { match instruction { // update mask or insert value at all relevant addresses Instruction :: BitMask ( new_mask ) => mask = * new_mask , Instruction :: Write ( ( address , value ) ) => { // apply ones to address let address = * address | mask . ones ; // iterate over all combinations of floating bits and add value to memory addresses for ( mask , none ) in BitMaskNones :: from ( & mask ) { memory . insert ( ( address & ! mask ) | none , * value ) ; } } } } // return memory memory }
tag::run_v2[]
Solve part 1
tag :: run_v2 [] Solve part 1
instructions
&[Instruction]
instructions
&[Instruction]