Added logic for part 1b solution

Untested