fn simulate(m: &Map, iterations: u32, short: u16) -> u32 {
  let (mut m1, mut m2) = (m.clone(), m.clone());

  let mut values = Vec::with_capacity(1024);
  for i in 0..iterations {
    mem::swap(&mut m1.data, &mut m2.data);
    m1.flip(&mut m2);

    if i >= short.into() {
      let this_value = m2.value();
      values.push(this_value);
      if let Some(seq_len) = has_repeating_sequence(&values) {
        // println!("Found {}-value repeating sequence at {}", seq_len, i);
        // values
        //   .iter()
        //   .rev()
        //   .take(seq_len)
        //   .rev()
        //   .for_each(|&x| print!("{}, ", x));
        let pending = (iterations - 1 - i) as usize;
        // `- 1` because `pending` is count while we want index
        let idx_into_seq = (pending - 1) % seq_len;
        let base = values.len() - seq_len;
        return values[base + idx_into_seq];
      }
    }
  }
  // println!("{:?}", m2);
  m2.value()
}
/** Runs `iterations` of simulation but try short-circuiting after
`short` times */
Runs `iterations` of simulation but try short-circuiting after
`short` times
Runs ` iterations ` of simulation but try short - circuiting after ` short ` times
fn simulate(m: &Map, iterations: u32, short: u16) -> u32 {
  let (mut m1, mut m2) = (m.clone(), m.clone());
  let mut values = Vec::with_capacity(1024);
  for i in 0..iterations {
    mem::swap(&mut m1.data, &mut m2.data);
    m1.flip(&mut m2);
    if i >= short.into() {
      let this_value = m2.value();
      values.push(this_value);
      if let Some(seq_len) = has_repeating_sequence(&values) {
        // println!("Found {}-value repeating sequence at {}", seq_len, i);
        // values
        //   .iter()
        //   .rev()
        //   .take(seq_len)
        //   .rev()
        //   .for_each(|&x| print!("{}, ", x));
        let pending = (iterations - 1 - i) as usize;
        // `- 1` because `pending` is count while we want index
        let idx_into_seq = (pending - 1) % seq_len;
        let base = values.len() - seq_len;
        return values[base + idx_into_seq];
      }
    }
  }
  // println!("{:?}", m2);
  m2.value()
}
fn simulate ( m : & Map , iterations : u32 , short : u16 ) -> u32 { let ( mut m1 , mut m2 ) = ( m . clone ( ) , m . clone ( ) ) ; let mut values = Vec :: with_capacity ( 1024 ) ; for i in 0 .. iterations { mem :: swap ( & mut m1 . data , & mut m2 . data ) ; m1 . flip ( & mut m2 ) ; if i >= short . into ( ) { let this_value = m2 . value ( ) ; values . push ( this_value ) ; if let Some ( seq_len ) = has_repeating_sequence ( & values ) { // println!("Found {}-value repeating sequence at {}", seq_len, i); // values //   .iter() //   .rev() //   .take(seq_len) //   .rev() //   .for_each(|&x| print!("{}, ", x)); let pending = ( iterations - 1 - i ) as usize ; // `- 1` because `pending` is count while we want index let idx_into_seq = ( pending - 1 ) % seq_len ; let base = values . len ( ) - seq_len ; return values [ base + idx_into_seq ] ; } } } // println!("{:?}", m2); m2 . value ( ) }
Runs `iterations` of simulation but try short-circuiting after
`short` times
Runs ` iterations ` of simulation but try short - circuiting after ` short ` times
m
&Map
iterations
u32
short
u16