rustwasm / book

The Rust and WebAssembly Book
https://rustwasm.github.io/docs/book/
MIT License
1.75k stars 211 forks source link

[nit] Simplify game of life rules #141

Closed kunalb closed 1 year ago

kunalb commented 5 years ago

✋ A similar PR may already be submitted! Please search 🔎 among the [open pull requests][open-prs] before creating one. -> Searched, I didn't see anything similar.

Updating the Game of Life tutorial's code? Also send a PR to rustwasm/wasm_game_of_life! -> Will update with a link to the PR.

Now that you've checked, it's time to create your PR. 📝 Thanks for submitting! 🙏

For more information, see the [contributing guide][contributing]. 👫

Summary

Thank you for creating and maintaining the WASM book – I really enjoyed working through it.

I was a bit distracted by the complex Game of Life rules implementation, and thought it might make the code & logic simpler to collapse them based on the next state – any cells with 3 neighbors, or alive cells with 2 neighbors survive to the next iteration.

I adjust the match statement and the answer to the bitwise solution accordingly in this pull request.

(My editor also stripped some trailing whitespace; I can strip that from the PR if that's too noisy).

Thanks!

kunalb commented 1 year ago

Never got around to it, hopefully whitespace changes got pulled in otherwise.