Programming exercises

Afraits

Well-known member
Joined
Jan 28, 2005
Messages
73
Location
Manchester, UK
Ive recently been teaching myself C# & ADO.NET and having worked through a few books am reasonably confident about them. However my imagination (or it might be boredom as work is quiet) is lacking in trying to think up ways to use them in a more real application. If there were enough new projects coming in it would be okay as Id have real problems to practice with, but there arent so Ive been looking but not found much that impressed me.

Does anyone know of any good sites that contain programming exercises, ideally of varying levels of difficulty/complexitity? Answers/solutions to exercises are not necessary though probably useful.
 
Diesel said:
Ive done a few, we can collaborate on some if youd like

My favorite part of my VB6 class was getting those problems at the end of each chapter. Not the lame T/F or quick answer ones, the ones where they wanted you to solve a problem... and it seemed impossible, then you found the answer and everyone else in the class gave you hateful stares and flocked to be in your group for projects...

Wow, maybe thats why I like programming so much. Im always a nerd and odd person out, but in a programming class I was first person chosen!

Sure we can collaborate. I know its extra nerdy of me, but Im contemplating seeing if I can do them all. Some of them look quite advanced though :D
 
All of them huh? All 1546 of them!? How about one at a time. They are probably more difficult then they look at first... pick one out and well start there.
 
I wouldnt shoot for solving all. Even if you pick out the first 800, I think its safe to assume that most will be at least 2 hours - thats 1600 hours or roughly 200 days (8 hours/day). Thats a full year of doing almost nothing but solving these problems...

Im a nerd, too - math and computers.

-ner
 
I want to start from the beginning and just run right through.

Do you want to do this via email or these forums or a private forum (I have one set up)?

The first problem is "The Blocks Problem"

These are the goals:

The valid commands for the robot arm that manipulates blocks are:

* move a onto b

where a and b are block numbers, puts block a onto block b after returning any blocks that are stacked on top of blocks a and b to their initial positions.

* move a over b

where a and b are block numbers, puts block a onto the top of the stack containing block b, after returning any blocks that are stacked on top of block a to their initial positions.

* pile a onto b

where a and b are block numbers, moves the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto block b. All blocks on top of block b are moved to their initial positions prior to the pile taking place. The blocks stacked above block a retain their order when moved.

* pile a over b

where a and b are block numbers, puts the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto the top of the stack containing block b. The blocks stacked above block a retain their original order when moved.

* quit

terminates manipulations in the block world.

So, I see the best bet is to create a class:

RobotMover
-MoveOnto(A as Integer, B as Integer)
-MoveOver(A as Integer, B as Integer)
-PileOnto(A as Integer, B as Integer)
-PileOver(A as Integer, B as Integer)
-New(NumberOfBlocks as Integer)
-Quit()

From here I could see keeping the Array outside the class and have the methods return an array value, but then youll have to pass it in. Id rather keep the array within class and have a get property for it.

Any thoughts? Im at work, but Ill continue to work on it.
 
Last edited by a moderator:
What IM service do you use? I think communicating through email and IM would be the fastest.
 
Yeh, I think having an array within the class would be easier to manage...but it wouldnt be array. We need a jagged array, each row in the 1st dimension of the array can have n elements. This problem actually seems pretty simple. What are we coding in, C#?
 
Continuing with blocks...

This would be a great time to pick up UML to diagram this out...

Bear in mind that this is all psudocode and I havnt touched VB.net/C# so there will definately be mistakes!

RobotMover
-MoveOnto(A as Integer, B as Integer)
-MoveOver(A as Integer, B as Integer)
-PileOnto(A as Integer, B as Integer)
-PileOver(A as Integer, B as Integer)
-New(NumberOfBlocks as Integer)
-Quit()

Code:
point BlockOrder() //An array of points initiated in the constructor. 
     //Each point will reveal which position left it is then which height its at. 
int BlockQuantity //The number of blocks in the row. Determined through the constructor. 

-New(int NumberOfBlocks)
     //This sub will check for a valid # of blocks and assign to BlockQuantity      
     //Initialze the BlockOrder array. This has a length of BlockQuantity-1. 

-Quit
     //This sub will clear all variables. It could have the code to quit the actual application, 
     //but Id rather keep that code outside of the class in case I want to port this to ASP.Net. 
     //Then I we should be able to just use the class as it was in the windows application. 

-MoveOnto(A as Integer, B as Integer)
     //moves all blocks from A & Bs index to their initial positions. Great place for a private method to take care of this. 
     //Actually move A onto B.

-MoveOver(A as Integer, B as Integer)
     // Moves all blocks from on top of A to their initial position. 
     // Move block A over to the top of column B

-PileOnto(A as Integer, B as Integer)
     // Move all blocks on top of B to their initial position.
     // Moves the entire column A on top of B, but in the same order.

-PileOver(A as Integer, B as Integer)
     // Moves column A and places it on top of Column B

-Unpile(Block as Integer)
     // Removes all blocks placed ontop of Block to their initial positions. 
     // This is a private method to be used in multiple procedures. 

-point Blocks()
     //Readonly property which returns an array of points which represents the block positions.

Yes, I really do need to work out some standard, either UML or stick to VB.Net or C#
 
Actually, we could use a 1 dimension array, we would just indicate the end of rows by /0 or such. That might be easiest. The length of the array would be 2n. Or not, might be awkward to work with.

I like C#
 
Diesel said:
Actually, we could use a 1 dimension array, we would just indicate the end of rows by /0 or such. That might be easiest. The length of the array would be 2n. Or not, might be awkward to work with.

I like C#

Since the blocks will always be numbered 0 through n-1, I figured it was easiest to work with a single array of points.

The index would indicate which block it was, the x of the point would be its X location on the grid and the y would be the y location on the slide.

Then to draw them onscreen you just need to go through each of the items.
 
Anyone else want to join in? Maybe we could start the dotnetTeam. Get 10 good problem solvers, 1 problem a week, we could make a dent in the team standings.
 
Back
Top