semi brute force solution