The Playground doesn't run without the input.txt
file, so I haven't tested these points beyond compiling them. And I also don't know what the exercise was. But in terms of superficial code style:
- Instead of
.split("\n")
, you can also do.lines()
. I'm guessing, in this case, it makes no difference, but.lines()
handles line endings correctly for Windows, too. - In your main-function where you're iterating over
page_numbers
, you don't want to.collect()
right afterwards. The.split()
has turned it into an iterator, then the collect turns it back into aVec
and then the for-loop implicitly adds a.iter()
afterwards, because it needs to turn it back into an iterator to loop through it. If you just don't collect into aVec
, it can directly use the Iterator that came out of the.split()
. - Your
count_correct()
function takes theHashMap
as an owned value. Generally, you want your functions to take parameters as a reference, unless you actually need the ownership. So, if you change that to&HashMap
and then change where you call it tocount_correct(&rules_hash_map, page_numbers_line)
, then it works the same. In particular, cloning a whole HashMap in every cycle of the loop can use rather many resources. But cloning when you don't need to, can also lead to logical mistakes, as you might end up updating one clone of the HashMap, not realizing why it's not being updated everywhere.