Something to do

I just finished up programming fundamentals 1, I am not taking another programming class but want to still practice programming. Could someone give me a relatively simple program to write so I can practice? Keep in mind still very new to this. TIA
One of many similar sites, pick your own skill level.
https://edabit.com/challenges/cpp

I do not like code challenge sites. The vast majority of them, the problem is not how to code it, its how to solve their (poorly stated) word problems. A couple of the sites throw some good stuff at you though, like invalid input that you need to trap and handle, or excess input, to see if your code is fast enough to handle a bigger job than most classrooms provide. A couple of them are money pits, they want you to pay to be able to see the answer or in some cases, what the failures were. Try a few, but if you find you spend more time trying to unravel what they want you to do than writing the code, move on.

see if your book from your class has material you did not cover or good problem to do that you did not do for the class.

It would not go amiss if you simply walked through this site or learncpp site and studied each example code blcok for each of the stl containers, including strings, and also used each algorithm once.
for example, try to re-create C's rand() with <random> tools following the examples. Try to time your code using <chrono>. If this gets boring, look for a problem to solve that uses the ideas -- try coding the problems in your current text book using these containers and algorithms, try to write as few functions as possible and rely mostly on what is in the language already to see if you can do them with that style.

jonnin wrote:
I do not like code challenge sites. The vast majority of them, the problem is not how to code it, its how to solve their (poorly stated) word problems. .....


I find with sites such as Project Euler, one has to think like a mathematician, with some programming to help out. Problem 1 is a prime example: It's easy to write a for loop to go through all the numbers, but the most efficient way involves a formula. That is the whole idea, find the most elegant way of doing the problem.

Problem 67 is an example where an efficient algorithm is very important:

ProjectEulerNo67 wrote:
NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, as there are 2^99 altogether! If you could check one trillion (10^12) routes every second it would take over twenty billion years to check them all. There is an efficient algorithm to solve it. ;o)


So I think it is more about logic than coding. Some of the problems I have solved (admittedly one of the easier ones ) by pure logic, no need for any code except for a single expression on the calculator.

But for Problem 18 & 67 it was educational for me to create what I call an Xmas Tree Data structure where a node can have 2 parents, 2 siblings, and 2 children, with nullptr for those nodes on the edges. Also an iterator that traverses the tree. Note that I have got that far, but still haven't solved it yet ;+)
In my experience, not counting dumb CRUD applications, 98% of the problems in software are engineering. E.g. "choose the right common data structure/algorithm for this", "schedule tasks properly so things run smoothly", "choose a design that minimizes programmer errors and/or limits their impact". The remaining 2%, which are the sort of problems challenge sites focus on, are theoretical and are either solved but obscure, or unsolved and very rarely worth tackling in a real project.
For example, if you were working on an application that could use public key cryptography but RSA didn't exist, it would be foolish to attempt to invent it within the project's budget.

I think that's where those sorts of sites fail, from a pedagogical standpoint. They don't provide a realistic perspective of the profession.
Oh well, for me, at least it is worth it for the challenge alone. And I do get some satisfaction from writing some good code, presumably some other coders do too. I would rather do Euler Project than Sudoku or Spider with 4 suits.

I find Sudoku to be the same process each time. There are bigger puzzles, like 5 grids overlapping, but they just take longer - still the same process.

On my version of Spider, it tells one if it is possible or not to win, and backtracking doesn't increment the move count. The game sometimes requires seemingly illogical moves, so in the end the whole thing is trial & error. Some convoluted games can take approximately 1200 moves to win, while others are about 200 moves.
Problem 67 is an example where an efficient algorithm is very important:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
   const int ROWS = 100;
   vector<int> A( 1 + ROWS ), B( 1 + ROWS );

   ifstream in( "triangle.txt" );
   in >> B[1];
   for ( int r = 2; r <= ROWS; r++ )
   {
      A = B;
      for ( int j = 1; j <= r; j++ )
      {
         in >> B[j];
         B[j] += max( A[j-1], A[j] );
      }
   }
   cout << *max_element( B.begin(), B.end() ) << '\n';
}
Last edited on
@lastchance


1
2
3
4
5
6
7
8
using PE67  = lastchance.ProjectEuler.Solution67.Algorithm;
PE67 = Complexity::Simple;
PE67 &= Sophistication::Clever;
PE67.Overall = Beauty::Elegant;

Mathematicans.Win = true;

TheIdeasMan->ThingsLearnt = Quantity::Lots;


Very well Done! :+D Thank you.

In PE 67 forum It's interesting to read a math proof of the solution. Cheers.

Edit: Check out this code in the K language:

{y+|':x}/|.:'0:`triangle.txt

That is the whole of the code: Crikey !!

https://en.wikipedia.org/wiki/K_%28programming_language%29
Last edited on
Topic archived. No new replies allowed.