Test driven development. Instead of getting something to work endlessly only to find out that it’s not working, instead of writing code and checking if it works, write some tests first and do the minimum work possible to pass those tests.
Create a series of tests or constraints for you to solve. For Example: Requirement Driven Development