What do you do when you don't know how to solve a problem?

I don't mean how,to code the solution though. I was looking at spoj this morning and I forget the problem but the answer was done in a simple for loop. I know how to do a for loop but when I looked at the problem it didn't jump out "oh, throw it in a for loop", if that makes sense. So, when it comes to how to actually solve a problem, not just coding it, hiw,do you develop that skill?
I feel like this is a dumb question but I do struggle with this a lot. Anyway, thanks for any input.
Last edited on
This book may be worth a read: 'How to Solve It by Computer' by Dromey
https://www.amazon.com/Solve-Computer-Prentice-Hall-International-Science/dp/0134340019

Inspired by Polya's classic 'How to Solve It' https://en.wikipedia.org/wiki/How_to_Solve_It
Looks like an interesting book, I will definitely check it out, thanks!
search the web, dig through your algorithms/problem solving books, look at the problem differently, solve it by hand / figure out how you would do it as a human, ask peers. Adapt what you see from your sources, try to find a technique that can crack it.
Thank you. I need to invest in some good problem solving books. My time is so limited I spend all of it trying just to learn the language but then I really struggle with how/when to apply what I learn. I guess maybe my brain just doesn't work like a programmer yet.
The way I find works best for me when stuck with such is ask at work.... I don't work in IT/programming etc. so explaining the problem to someone else I have to 'dumb' it down to its most basic it can be, and I find doing that I work it out myself before I even finished explaining it.

So as friend/family who is not know anything about programming may work, may not but worth a try I guess......
Maybe I can work problems out with my son. He's 8 so would have an interesting method I'm sure.
I think many of the online coding sites pose problems that are quite difficult to solve, especially for beginners. So maybe you're looking at problems that are too hard. And don't think that makes you a worse programmer - those sites are full of problems that you'll never see in your programming career.
Yeah, that's a problem too. 90% or more of what's online isn't practical application so it doesn't make much sense. I understand things much better when I can see it in a real world case but those are hard to find.
I think ultimately I still need,to spend a great deal more time on problem solving programming books more so than syntax type books. I know I can Google enough to overcome syntax problems but knowing where and how to start will be a huge help.
Skip the competition junk. Start by trying to solve the 'classics' ... I highly recommend an old datastructures and algorithms book to get started. Then move to a pure algorithms book. Then grab a numerical algorithms / math book. Those would take a couple of years to work through. And working though them lets you mix and match the themes behind those algorithms into new ideas and new algorithms. It goes deeper... dynamic programming ideas, data driven ideas, multimedia processing algorithms, graphics, ... and each thing you study builds your vision into how to approach problems and what might work.

The tried and true approach works somewhat. Solve the problem on paper, by hand, and firm up the steps you need to take to do it. Then see if you can do it with less steps or another way. Eventually you can generate steps that lead to an algorithm that leads to code. There is always someone who can find a better way, building off what you did or not, but this gets it done.
Last edited on
Very interesting, thank you. I'll dig through my files and see which data structures and algorithm books I currently have. Are there any in particular that stand out?
All my books are older than most programmers lol. I got nothing modern.
Lol oh. The only one I have right now is introduction to algorithms. I thought I had a few, I'll keep looking
Registered users can post here. Sign in or register to post.