Problem 12

a brute force solution which is kinda slow