Make it work
First, you gotta make the code work. Even if it's totally unmaintainable, duplicates code, and performs slower than molasses, at least it works. That beats beautiful code that doesn't work any day. Code has gotta do what the users want.
A number of times over the years, I've worked on a programming problem I found challenging at the time. To make progress, I backed-off trying to write good code, and just tried to write something that would work. Once you've got it working, then you can say with 20/20 hindsight, "Now that I know what I need to know, knowing what I know now, here's how I would do it differently."
Some people interpret the first two steps, make it work and make it right, as meaning that code can somehow work even if it doesn't work right. That's not what's meant here. Work means that it passes your JUnit tests, even if it's really ugly code. Right means that it's well designed code that also works, which I'll talk about next.