For part one I did just stupid nested for loops, visualizing it would be rather boring so you're only getting the hits. For part two I actually used bit masks and:ed together.