solution for #4. kind of brute force, but whatever.