LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What are some "classic" programming exercises? (https://www.linuxquestions.org/questions/programming-9/what-are-some-classic-programming-exercises-4175472819/)

NeXuS_2006 08-09-2013 04:05 PM

What are some "classic" programming exercises?
 
I've been learning java/android for about 4 months, have been dabbling in php, sql, and C/GTK+ along the way, and starting to feel somewhat comfortale in at least java/android.

What are some of the classic things everyone learns to do? Do you write basic html engines from scratch? Make your own string class just to see if you can?

I'm just looking for ideas of things to do, not for a practical purpose, but to learn along the way, things you might do in the first 2 or 3 years of a comp sci degree.

dugan 08-09-2013 06:27 PM

Fizzbuzz is one of the classic job interview questions...

chrism01 08-09-2013 09:24 PM

There are many, but a few algorithmic ones are tic-tac-toe, solving various chess problems; not chess games, but special problems like max num of eg queens on a board http://codegolf.stackexchange.com/qu...queens-problem (sometimes known as 'golfing' problems) & https://en.wikipedia.org/wiki/Knight%27s_tour.

Try to program eg linked lists, hashes etc from scratch ie no modules (think basic C code only, inc ptrs).

bigearsbilly 08-15-2013 03:42 PM

"game of life" is always good fun.

dwhitney67 08-15-2013 04:01 PM

A simple, but classic challenge, is the Towers of Hanoi.

Ok, well, I'm not sure if that is a classic. It probably should be referred to as "classical" (as in old)... it was a teaser presented to 1st year CS majors many, many, many years ago.

bigearsbilly 08-15-2013 04:10 PM

Towers of hanoi!!!

Yes we all never bored with lectures on that at college!

NeXuS_2006 08-16-2013 02:09 PM

Thanks guys, those are the kinds of things I am looking for.

I also found these exercises/puzzles, same author as "The Pragmatic Programmer."
http://codekata.pragprog.com/

bigearsbilly 08-16-2013 03:58 PM

this is the game of life I mean:

https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

markush 08-16-2013 04:16 PM

The "Sleeping Barber Problem"

Markus

frieza 08-16-2013 05:43 PM

i remember a simple one from my programming class in college
create a program that outputs this
Code:

                  *
                * *
                * * *
              * * * *
              * * * * *
            * * * * * *
            * * * * * * *
          * * * * * * * *

perhaps too simple?
make it so it takes input on how many rows tall

NeXuS_2006 08-16-2013 07:24 PM

All good suggestions, I have plenty to stay busy with now.

Thanks for the tree idea, spent a couple hours with it, lots of fun. Here is the code I wrote.

I'll be working on the others too.

psionl0 08-17-2013 06:52 AM

Quote:

Originally Posted by NeXuS_2006 (Post 5010683)
Thanks for the tree idea, spent a couple hours with it, lots of fun. Here is the code I wrote.

Your link doesn't work for me. But why do you need a separate web page for 7 lines of code?
Code:

10 INPUT "how many rows? ",n
20 spaces = n
30 FOR i = 1 TO n
40 spaces = spaces - 1:IF i = n THEN 60
50 FOR j = 1 TO spaces:PRINT " ";:NEXT
60 FOR j = 1 TO i:PRINT "* ";:NEXT:PRINT
70 NEXT i


911InsideJob 08-17-2013 08:16 AM

My Radio Shack Color Computer (CoCo, original 1) booted up straight into BASIC. The book that came with it had programming excercises like Russian roulettte. Prompt the user to press enter, use a random number generator, output click, click, bang you're dead. ;)

danielbmartin 08-19-2013 08:49 AM

Quote:

Originally Posted by frieza (Post 5010650)
i remember a simple one from my programming class in college
create a program that outputs this
Code:

                  *
                * *
                * * *
              * * * *
              * * * * *
            * * * * * *
            * * * * * * *
          * * * * * * * *

perhaps too simple?
make it so it takes input on how many rows tall

An interesting problem, one I had not seen before. I wrote an awk solution:
Code:

r=11  # r = number of rows in the output file
# bs = blank string; as = asterisk string; cs = combined string
awk -v r=$r  \
 'BEGIN{for (j=1;j<=r;j++) {bs=bs" ";as=as"* "}; cs=bs as;
        for (j=1;j<=r;j++) print substr(cs,j,j+r)}' >$OutFile

A question for expert awkers:
This code fragment creates a character string called cs.
Code:

for (j=1;j<=r;j++) {bs=bs" ";as=as"* "}; cs=bs as;
The string contains "r" blanks followed by "r" character pairs, each pair being "* ".

Is there a syntax which allows direct specification? Something like ...
Code:

cs=" "(r) "* "(r)
Daniel B. Martin

vdvluc 08-19-2013 08:33 PM

Producers and consumers: https://en.wikipedia.org/wiki/Produc...sumers_problem
Dining philosophers: https://en.wikipedia.org/wiki/Dining...ophers_problem


All times are GMT -5. The time now is 11:45 AM.