Ad
  • Custom User Avatar

    Hey thanks for translating this, I had fun solving it!

    My only suggestion is that the function signature look more like this:

    fn rule30(list: &[bool], n: usize) -> impl IntoIterator<Item=bool>
    

    Here's my reasoning:

    1. It feels more typesafe to use bool rather than u8 because any value except 0 or 1 are invalid for this problem.
    2. The number of iterations requested n would be ever so slightly nicer to work with if it were a usize. This allows the implementor to compute max allocation sizes without having to cast to usize themself.
    3. It's not clear that a Vec is necessarily the best datastructure to return. For instance, I found VecDeques easier to use since the world could be extended efficiently. It would also allow the use of BTreeMap<usize, bool>s (or some other ordered map) to be used, which some might find more ergonomic.
    4. I like that the initial input (list) is provided as a slice because that places the responsibility of allocating the input on the caller, not the implementor, but prevents mutation (like if a Vec were provided instead).
  • Custom User Avatar

    I've reviewed your solution and tests, and I've written a working Haskell solution, does that count?

  • Custom User Avatar

    Looks good to me. I hope this gets approved!

  • Custom User Avatar

    Have you heard of that cool thing where an Iterator<Item = Option/Result<T>> can be collected into a Option/Result<Vec<T>>? I think it would let you say .collect().unwrap() instead of .map(Option::unwrap).collect().

  • Custom User Avatar

    Nice! I wish slice::array_windows was stable, that would let you do something like:

    .filter(|[a, b, c]| {
      a != b && b == c
    })
    
  • Custom User Avatar