#AdventOfCode #Day3
-
Soooo... I think my "high-level brain" is starting to conflict with #rust.
This works, but:
* clippy wants to me to rewrite a loop to use iterators, but I don't get why it'd be better
* I think I should be using pass-by-reference rather than values in a few places
* that type on my parse function looks scary
* I am using Vec but this all looks pretty static so I feel it should all be arrays? dunno.
* I miss named argumentshttps://gist.github.com/riffraff/d674119aa3740275967fd6f14b77cba6
-
Soooo... I think my "high-level brain" is starting to conflict with #rust.
This works, but:
* clippy wants to me to rewrite a loop to use iterators, but I don't get why it'd be better
* I think I should be using pass-by-reference rather than values in a few places
* that type on my parse function looks scary
* I am using Vec but this all looks pretty static so I feel it should all be arrays? dunno.
* I miss named argumentshttps://gist.github.com/riffraff/d674119aa3740275967fd6f14b77cba6
@riffraff I think clippy just wants you to avoid you using indexing. You can mix for loops with iterators. So for example use `for value in numbers.iter().take(wanted) {` instead of the range. Which also makes the calculation of `end` easier to understand.
-
@riffraff I think clippy just wants you to avoid you using indexing. You can mix for loops with iterators. So for example use `for value in numbers.iter().take(wanted) {` instead of the range. Which also makes the calculation of `end` easier to understand.
@tamme indeed, but I do want the index in this case (it's part of the return value), so I need enumerate() and max_by_key() and at that point it becomes messier to my eyes 🤷♂️
EDIT: although I guess I can use enumerate and the same max, and that's what you meant with mixing for an iterators 🤔