Part one uses bit manipulation to build up the binary numbers directly one digit at a time.
Part two clones the input vec then uses retain to efficiently discard numbers that don’t meet the criteria.
vec
retain