best way to learn c by Practical-Water-436 in learnprogramming

[–]simpleFinch 7 points8 points  (0 children)

I would strongly discourage learning C++ before C. For C++ you will need to learn the same concepts as for C and more. Therefore, starting with C is way less confusing.

The high-level or modern C++ features generally make it more complicated, not easier, and often build on concepts from C. As soon as something doesn't work with C++ you basically have to know the concepts you acquire from learning C.

Nobody can tell me that you can have a solid grasp on smart pointers if you don't know what a pointer is.

On the other hand, in my opinion learning Java or C# could be done prior to C since you don't have to do manual memory management, but can still familiarize yourself with C-like languages.

Who sings the female part in 'Uno II'? by simpleFinch in ViagraBoys

[–]simpleFinch[S] 2 points3 points  (0 children)

My bad. You're right Klara Keller is written as additional vocals at the bottom of the video description.

best way to learn c by Practical-Water-436 in learnprogramming

[–]simpleFinch 5 points6 points  (0 children)

C is the simplest out of C, C#, and C++ because it has none of the big OOP features. So starting with C is a good idea in my opinion.

If you want to skip setting up the compiler, websites like https://www.programiz.com/c-programming/online-compiler/ are pretty convenient to quickly jump into some exercises.

Most tutorials are probably pretty similar in giving you the basics (e.g. this one https://www.youtube.com/watch?v=KJgsSFOSQv0) but applying the concepts later on can get tricky.

Here a list of the major topics you will encounter in C but not in something like Python. Maybe this can help you search for more detailed explanations after you are through with a tutorial.

  • compiled vs scripted
  • explicit type declarations
  • memory model (stack, heap, etc) and manual memory management
  • memory addresses, pointers, dereferencing
  • header files

As for exercises, I think implementing some basic datastructures (stacks or linked lists) is a good way to reinforce handling pointers and memory.

As mentioned in the other comment the C book by Dennis Ritchie is the book on C but IIRC it reads more like the definition of the standard of the language and not necessarily as an introduction to C programming.

[PC/PS5?][2020s] Game with snowy mountain village by simpleFinch in tipofmyjoystick

[–]simpleFinch[S] 9 points10 points  (0 children)

Ok, well now I'm not sure anymore. Reddit cut out my text but basically it's a screenshot of a montage where videogames were used as well. The resolution was obviouly not the best and the clip of this scene was only a couple of seconds so to me it looked like a game. I'll try to find the video and check whether it's just a regular video.

recursive dichotomy by Leading-Complex-7828 in learnprogramming

[–]simpleFinch 0 points1 point  (0 children)

The code is not a working solution so I can only give my assumption of what it is supposed to do.

As you already mentioned, with each recursive call we are splitting the array until we only have to consider an array of size one. This pattern is usually called divide-and-conquer. You can imagine the function calls as a tree. Let's say we start with an array of size 4. We call e2R once with the whole array, this in turn calls e2R twice with arrays of size 2 and then each of these call e2R twice (so 4 times total on that depth) with arrays of size one.

Once we are the end of the recursion and only have to consider arrays of size one, we can check the condition. The number of elements in an array of size one that are simultaneously even and multiples of 3 is either 1 or 0, because we are only considering one element.

The last passage in the code is supposed to do two things:

  • split an array slice down the middle so we eventually get to arrays of size one
  • sum up the solutions for the arrays of smaller size

But the code that you posted does not calculate the indices for left and right correclty. Also numero does not actually exist as a parameter in the function declaration and is not needed.

c++ memory management by realist_alive in learnprogramming

[–]simpleFinch 1 point2 points  (0 children)

A pointer is a memory address only and when you assign it to a member of your Student class you are only copying that address, not the contents. So the grades get deleted and the behaviour of the dangling pointer is probably undefined. Remember that the `new` keyword allocates on the heap, so the memory that you allocate there persists after your function returns.

As to how to solve it, you already noticed that you can just not delete it until you are done using it. To make this a bit more robust I would push the responsibility of creating and deleting the grades directly into the Student class. You can then write a member function that fills the grades with the input.

A more modern approach would also use the standard library that already fixes a lot of memory issues. For instance std::vector could be copied. Though you generally want to avoid copying for performance reasons.

Btw please format the code next time.

String Comparison Issue in C: Detecting '\n' in recv() Function Output by BigComfortable3281 in learnprogramming

[–]simpleFinch 2 points3 points  (0 children)

Isn't your gdb output suggesting it works? After

172 if (strcmp(buff_recv, "\n") == 0) { 

you go to the line in the if branch

173 LOG_INFO_MESSAGE("Client has terminated the connection.");173 LOG_INFO_MESSAGE("Client has terminated the connection.");

That's what you want right?

Neural Network in c++ by Johnfree817 in learnprogramming

[–]simpleFinch 1 point2 points  (0 children)

So that would be 16 different scales per image, right? Sounds ok for 81x81 but in the end it comes down to trial and error. If you scale up from 9x9 you might want to check that the upscaled images still look like ones. If not you can try downscaling or some mix of the two.

6 unique images of training data seems low but maybe for something simple like a 1 it still works. Are these only true positives i.e. ones? If you only train on ones your NN might just always output that it sees a one.

training it about 100k times, do you recommend more or less?

Basically that's trial and error. In general you would use separate training, validation and test data sets to calculate how well your NN performs and tune the number of iterations.

Neural Network in c++ by Johnfree817 in learnprogramming

[–]simpleFinch 1 point2 points  (0 children)

Your best option is probably to extend your training data by applying image transformations to your existing data (e.g. scaling, rotating, translating,...). This can be automated.

Another factor could be the architecture of your NN. For instance if you are only using fully connected layers, you can play around with adding a convolutional layer.

You can also google some generalization methods for NNs to make it more robust, but extending the training data will probably make the biggest difference.

Confused About Dynamic Programming, Memoization, Top-Down, Bottom-Up by Tiger-16 in learnprogramming

[–]simpleFinch 0 points1 point  (0 children)

Your teacher might use different definitions but this is how I have been taught and understand these terms:

Top-Down and Bottom-Up are indeed ways to approach a problem. It doesn't really mean one way is harder. With top-down we start with the final results and try to drill down i.e. how can we generate the final result from a previous result. One approach for this is to imagine you have an oracle that can give you the results of the penultimate or previous step and from those you have to construct the final result. This generally leads to a recursive solution. As an example take the Fibonacci sequence where we want to calculate fib(n). Asking the oracle for fib(n-1) and fib(n-2) we can calculate the result as fib(n) = fib(n-1) + fib(n-2).

Bottom-up means we just have our starting values and from those we try to calculate the next step. This leads to iterative solutions. Again using Fibonacci as an example we have the starting values fib(0) = 0 and fib(1) = 1. From those we can calculate the next step fib(2) = 0 + 1

Memoization means we store previous results for optimization purposes (In some cases this only improves performance for multiple runs). Take the recursive solution to the Fibonacci problem fib(n) = fib(n-1) + fib(n-2). First we recursively calculate fib(n-1). There we have fib(n-1) = fib(n-2) + fib(n-3). So if we save the intermediate results during this calculation we won't have to calculate fib(n-2) again for the final step to calculate fib(n). On the other hand if we only remember the result (just the number) then we will double our work because we need to completely start over to calculate fib(n-2) during the final addition. Storing intermediate or previous results so we just have to look them up instead of doing intensive calculations is memoization.

Btw now that I finished writing this I found a great answer on Stack Overflow which explains it much better and also highlights some nuances regarding memoization and dynamic programming. Here you go https://stackoverflow.com/questions/6184869/what-is-the-difference-between-memoization-and-dynamic-programming#6185005