Skip to main content
6 events
when toggle format what by license comment
Apr 15, 2020 at 14:27 comment added rogday @mb21 I think it's a choice, but I'm learning rust just like you.
Apr 15, 2020 at 7:01 vote accept mb21
Apr 15, 2020 at 7:01 comment added mb21 Ah, of course. Can't believe I missed that... have been working too much with immutable structures (in other langs). One last question: is using methods instead of functions generally favoured in Rust? or is it more of a stylistic choice, where OOP people use methods and functional people use functions?
Apr 14, 2020 at 16:18 comment added rogday @mb21, that's not about efficiency, but correctness of algorithm - you can't mutate the board you are currently working on. I believe there is a dynamic programming solution, but I'm not sure. There could be 2 Vecs inside the Board, so that you don't reallocate every iteration and at the end of next_step you just make a swap. Or a cell can contain two states - current and future, which will improve data locality. If you care about efficiency I recommend using Vec<Cell> instead of Vec<Vec<Cell>>, so that there's no extra indirection.
Apr 14, 2020 at 15:45 comment added mb21 very cool thanks! I didn't know about saturating_sub and derive_more of course... hm.. but you still have to copy the whole board new_board = self.clone(); which doesn't seem very efficient? or is it some lazy cloning? couldn't find what clone does for Vec in the docs...
Apr 14, 2020 at 15:09 history answered rogday CC BY-SA 4.0