LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-09-2013, 04:05 PM   #1
NeXuS_2006
Member
 
Registered: Dec 2003
Distribution: Mint 15, Slack 14
Posts: 61

Rep: Reputation: 18
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.
 
Old 08-09-2013, 06:27 PM   #2
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,572

Rep: Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394
Fizzbuzz is one of the classic job interview questions...
 
Old 08-09-2013, 09:24 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,247

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
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).
 
Old 08-15-2013, 03:42 PM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,284

Rep: Reputation: 172Reputation: 172
"game of life" is always good fun.
 
Old 08-15-2013, 04:01 PM   #5
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,507

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
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.
 
Old 08-15-2013, 04:10 PM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,284

Rep: Reputation: 172Reputation: 172
Towers of hanoi!!!

Yes we all never bored with lectures on that at college!
 
Old 08-16-2013, 02:09 PM   #7
NeXuS_2006
Member
 
Registered: Dec 2003
Distribution: Mint 15, Slack 14
Posts: 61

Original Poster
Rep: Reputation: 18
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/
 
Old 08-16-2013, 03:58 PM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,284

Rep: Reputation: 172Reputation: 172
this is the game of life I mean:

https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
 
Old 08-16-2013, 04:16 PM   #9
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
The "Sleeping Barber Problem"

Markus
 
Old 08-16-2013, 05:43 PM   #10
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,079

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
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
 
Old 08-16-2013, 07:24 PM   #11
NeXuS_2006
Member
 
Registered: Dec 2003
Distribution: Mint 15, Slack 14
Posts: 61

Original Poster
Rep: Reputation: 18
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.
 
Old 08-17-2013, 06:52 AM   #12
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.0
Posts: 510
Blog Entries: 2

Rep: Reputation: 68
Quote:
Originally Posted by NeXuS_2006 View Post
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
 
Old 08-17-2013, 08:16 AM   #13
911InsideJob
Member
 
Registered: Jul 2013
Distribution: Mint KDE
Posts: 74

Rep: Reputation: Disabled
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.
 
Old 08-19-2013, 08:49 AM   #14
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,067

Rep: Reputation: 284Reputation: 284Reputation: 284
Quote:
Originally Posted by frieza View Post
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
 
Old 08-19-2013, 08:33 PM   #15
vdvluc
LQ Newbie
 
Registered: Apr 2009
Location: Netherlands
Distribution: NetBSD
Posts: 19

Rep: Reputation: 3
Producers and consumers: https://en.wikipedia.org/wiki/Produc...sumers_problem
Dining philosophers: https://en.wikipedia.org/wiki/Dining...ophers_problem
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get "Print Screen" working under Gnome Classic cccc Debian 1 05-20-2013 03:16 PM
GNOME Shell to support a "classic" mode etech3 Linux - Desktop 2 11-22-2012 11:25 PM
LXer: A More "Classic GNOME" Session Lands In Ubuntu 12.04 Precise Pangolin LXer Syndicated Linux News 0 02-13-2012 01:00 PM
Socket Programming making use of "select()" and "writefds" johncsl82 Programming 10 11-13-2011 12:27 PM
"Classic" GNOME? Erik_the_Red Linux - Software 2 06-30-2005 02:50 AM


All times are GMT -5. The time now is 08:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration