Writing code is very very often a big part of understanding any new problem. It's just that you should be quite comfortable discarding that code. Refactor mercilessly and all that.
Writing code that solves the problem is a huge way of proving you understand the problem.
Sometimes you can't have realistic data without writing some code first, that will allow you to gather that data.