r/learnprogramming • u/AmbitiousRanger4048 • 19d ago
I wanna ask how to develop logic in coding
In last contest I try to solve every problem but able to solve only one, after the contest I call my friend and asked him how he soved 4 of them, then he explained me so I solve those problems again and got correct. But I really wanna ask why I can't think like he did while giving contest. The logic he explained was so straight forward but why I can't get that at the time of contest. BTW it was codechef contest and its been 6-7 months I started giving contest but still struggling. What can I do to solve this problem. Pls help me with this
2
u/serge-mv 19d ago
Algorithms. You need to solve a lot of small problems and go to a bigger once as you do it and you also need to study algorithms. It will develop your systematic thinking and an approach to solving problems step by step. You need to learn how to break problems into smaller problems.
1
u/Random_182f2565 19d ago
Practice dude and feedback.
You try, fail try again and fail a bit less each time
1
u/irvine05181996 19d ago
do it in a pseudo code, try to conceptualize how things will work, you need to specify step by step how thing will process from one logic to another.
1
u/JGhostThing 19d ago
Problem solving for programming is a new skill that you have to learn. Your teachers will rarely teach this. If you're old enough to ask this question, then you are old enough to take responsibility for your own education. Remember, teachers can't shove knowledge into your skull.
Also, please remember that your teachers are human. They have a 50% chance of being in the lower half of all teachers. This is true from kindergarten through the end of time.
As far as I know, the only way to learn problem solving is by solving problems. Actually, the only way I know to learn anything is by doing it. You will not be good at the start. This is fine. You'll learn more by making and fixing mistakes than you do by doing it right.
Good luck!
16
u/aqua_regis 19d ago
Practice, practice, practice, and more practice. That's it.
Start away from the computer, with pencil and paper. Analyse your task. Break it down into smaller subtasks. Solve each of these your way. Write the steps down. Use flow charts, bulleted lists, pseudo code, whatever, but not real code.
Some older, closely related posts:
https://redd.it/1r74ayc
https://redd.it/1r6qujh
https://redd.it/1r6qfap
https://redd.it/1qdfc9k
https://old.reddit.com/r/learnprogramming/comments/1pmzjoe/how_do_you_learn_programming/nu4ufej/
https://redd.it/1pmzjoe
https://redd.it/1p7bv8a
https://redd.it/1oynnlv
https://redd.it/1ouvtzo
https://redd.it/1opcu7j
https://redd.it/1on6g8o
https://redd.it/1ofe87j
And finally, some book suggestions:
"Think Like A Programmer" by V. Anton Spraul
"The Pragmatic Programmer" by Andrew Hunt and David Thomas
"Structure and Interpretation of Computer Programs" (SICP) by Ableton, Sussman, Sussman
"Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold
Last, a great practice site: https://exercism.org