brute method for 0005, needs optimising