+ 8
How to analyze a problem?
Hello everyone! I'm a computer science student and programming is a subject I'm passionate about. However, I am having enormous difficulties in finding solutions to solve even the simplest problems (for example: write a program that reads a sequence of numbers and searches for the maximum value.) What could be the best technique to try to solve these types of problems or at least try to understand the problem? (At the moment I'm studying the FOR and While and Do While interaction cycles). (Sorry For my Bad english).
49 Respuestas
+ 14
I don't know if your curriculum allows for that, but solving problems by translating them to code... let me emphasize...
***
has to be practiced, and there is no shortcut!
***
The trick is to start with easy problems. There is no problem, that's to easy. If you can't solve a problem, look for dumber tasks. ;-)
It doesn't remain this way. With every little problem you manage to solve... emphasis again...
***
on your own, without rote memorization!
***
... you become a little bit stronger, and over time it adds up.
There is no other way. You have to start at the point where you are at now, and train hard.
+ 8
That's quite a common problem with most of the beginners. All you should do is, take a paper and a pen and solve it mathematically. It doesn't have to be maths all the time but logic that you require to solve a problem.
Coming to your question on maximum value search. You can do it in many ways-
1) Sort the array elements in ascending order and print the last element or you can do vice-versa.
2) declare a variable int x= 0.
Use a for loop to iterate over the array elements and you can do-
if(arr[i] > x){
x = arr[i];
}
// print the value of x
Consider an array- int arr[] = {4, 7, 2, 5};
Apply this to the above and you will get the result.
+ 7
Hi,
go another way:
Study solutions until you understand each step.
Pencil and paper are your best friends at the moment.
If you think, you understand fully, code the solution by heart .
Try until you succeed.
The situation is serious. But training does the job.
The best chess player do it similarly.
+ 7
First break a problem down into smaller parts.
+ 6
Computer_King20 great!
+ 6
Computer_King20, alright then.
Well, if you don't understand the explanations, you might believe me and start at a lower level.
I'm someone who started without real aptitude myself (spent my life before with totally different stuff) and needed quite a bit of time until I figured out several things. And that voyage hasn't ended either.
You can not force this! You won't grow muscles if you can't even lift the barbell.
You need to start all the way at the bottom and work your way up.
Take user input and print it backwards.
Let the user enter a few numbers and add them.
Make a simple Stone-Scissors-Rock game.
Whatever it is, with every little exercise you will get better.
Trying to force this understanding into your head will lead you nowhere, you'll just be spinning your wheels. We've seen that before here on Sololearn.
+ 5
To understand this, let us take an example. Understand that you have a lot of coins. The largest coin represents the biggest digit and the smallest coin represents the smallest digit. You have a hole through which you have to withdraw all that money. The size of the hole is equal to the size of the largest coin. This means that in order to identify the largest coin you have to remove all the small coins from that hole and the coin does not come out of that hole, it means that coin is the biggest digit and you get your answer here.
+ 5
Yeah, Computer_King20, and that's why I'm telling you:
Look for a problem that you *can* solve, and postpone problems you can't figure out yet.
After you have done ten easier problems, you may have improved enough to figure this one out as well.
However, it would be of no use and a waste of a good task, if we just told you how to do it. That's not what these tasks are made for.
You need to study the language and practice it enough until you start to naturally come up with ways to translate task to code.
+ 3
Computer_King20
maybe it will always be your weak point.
Some brains are not made for it.
But no way out. It is a must have
+ 3
HonFu Thanks for your suggestions. now I'm trying to recover starting from the problems that started at the beginning of the school year. Hopefully some light bulb will turn on in my mind.
+ 3
Too hard.
Look for *way* simpler problems. And learn a bit of C first, you need to at least figure out the basic logic of input, output, data, loops and conditions.
+ 3
Sonic for example, how would you divide the exercise of the square into small parts that I said before?
+ 3
Computer_King20 it's all about positioning and knowing how many spaces to leave vertically and horizontally before the top left location of each square.
+ 3
Break the problem to many simpler problems. Like, first focus how to read a sequence of number . Secondly, try to create a code which creates a array of numbers from the sequence, Thirdly, a code which keeps track of the maximum number from the created array .etc...
Keep thinking and code every simple problem's solution as a function. Now, try to accumulate various functions into solving the problem.
Also, your code may work but you may still feel there is a better way to do it. Then, try to optimize every function without hindering the output and return value. That way you'll discover better ways to solve many problems for future. For example, once you start writing independent function for simpler problem, you can reuse those functions for future complex problem.
https://code.sololearn.com/cAymcYoa0eBN/?ref=app
Here in the above code I've created various functions and classes.
- A prime number checker (function)
- A divisiblilty checker (function)
- A range of number generator (function)
etc.
+ 3
Computer_King20 some problems are to be solved keeping more than one things in mind. I myself call them multi-dimensional problems.
You'd have to keep track of two or more things at the same time. Which is not easy (for me also)
The problem of concentric square in my view is multi-dimensional(2D).
I suggest you, to solve some linear problems(or 1-dimensional problems) first because multi-dimensional problems are really hard.
It requires a lot of focus, where you'd have to keep a pen and paper or some logging to see the pattern of the data.
Example of what I call multi-dimensional problem -
It's not easy to understand the code. But, it's ok. because sometimes I also can't understand my own code.
https://code.sololearn.com/cTJdb6cjJgVQ/?ref=app
+ 2
Practice makes perfect. Look up coding practice or something similar on Google and you'll find plenty interesting quests.
+ 2
Blabla Blablabla unfortunately I do a lot of practice staying even a few hours to solve a problem of this type. But unfortunately I can't reason to find the solution. Sometimes I also manage to set it up well but then, at a certain point, I get stuck and I can no longer continue.
+ 2
HonFu Yes, I understood some things to solve this problem but the problem is to code it. If I draw on a sheet in 3 squares, I notice that some * coincide on the same line. Then I realized that I have to initialize a counter in a cycle for me to print the asterisks and spaces. But trying to code it, I have a hard time putting the asterisks on one end and putting the squares inside each other.
+ 2
Computer_King20 for example, you first determine the coordinates of the centre. Then, for each square, you know that the top, left starting position is going to be half of its side length above and to the left of the centre.
+ 2
Sonic in coding how can I write this reasoning?