I'm reading dietel's java how to program and it talks about the the top down, stepwise refinement and using psudocode.
I decided to solve my next Euler problem(11) using this approach. While I know I could easily solve this problem (quicker even) without using this approach I am try to embrace good design techniques, because I am completely self taught , but aspire to one day be a professional.
my psudocode is below (3 stages of refinement) I want to know if I grasped the point of psudocode and stepwise refinement any advice/constructive criticism is much appreciated.
That looks a good example of how to refine an algorithm
One thing to beware: If you are going down, you must stop three rows from the bottom. If you are going right, you must stop three columns from the right.
Another thing which may make things quicker: If you go up for four squares, that give the same result as going down from three rows higher. That means you do not need to check all eight directions, only four of them. You can start going →, ↓ and ↘ from the top left corner, but only start ↙ from three columns to the right.
Branden Bobo wrote:my psudocode is below (3 stages of refinement) I want to know if I grasped the point of psudocode and stepwise refinement any advice/constructive criticism is much appreciated.
Well, I'm afraid I'm not familiar with the book; but I thought that the point of pseudocode was not to include implementation.
ie, You don't describe how something is going to be done, you describe what is going to be done - at least that's the way I was taught - so my pseudocode would never include references to things like Scanner's. To me, you should be able to translate pseudocode into any (or almost any) language.
Example - Suppose I had a piece of high-level pesudocode with the line:
Load grid data from file.
I might 'refine' that by breaking down the action, eg:but that's just the way I do it, and your book may have a completely different notion of 'refinement'.
BTW, one of the businesses of pseudocode is to allow you to refine the logic without resorting to actual code; and, as Campbell already pointed out, yours still contains a fair bit of redundancy:
1. You don't have to check all directions.
2. You don't have to check all 400 cells.
Isn't it funny how there's always time and money enough to do it WRONG?