aspose file tools*
The moose likes Java in General and the fly likes help creating algorithm for a problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "help creating algorithm for a problem" Watch "help creating algorithm for a problem" New topic
Author

help creating algorithm for a problem

Jorge Vazquez
Greenhorn

Joined: Nov 04, 2012
Posts: 7
I've been doing some exercises from codingbat, and I haven't figure out a way to solve this particular problem; may be someone could point me how to approach this. Thanks

http://codingbat.com/prob/p155405


Frank Hanner
Greenhorn

Joined: Jan 11, 2013
Posts: 4
Jorge Vazquez wrote:I've been doing some exercises from codingbat, and I haven't figure out a way to solve this particular problem; may be someone could point me how to approach this. Thanks

http://codingbat.com/prob/p155405




Do you see a pattern at all?

It's divided into n sections. Inside each section is n numbers (n*n). Each section is essentially counting down. With each section progression the number of zeros decreases by 1 and the appropriate number for the count down is inserted. If that get you thinking about it the right way, I'll show you some example code that might help.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4363
    
    8

Is the problem that you don't see the pattern, or is it that you see the pattern but are having trouble translating it to code?
Jorge Vazquez
Greenhorn

Joined: Nov 04, 2012
Posts: 7
Matthew Brown wrote:Is the problem that you don't see the pattern, or is it that you see the pattern but are having trouble translating it to code?

yeah, I see the pattern, I'm just having difficulty putting into code...
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4363
    
    8

Well, this is an outline of my first thoughts of how to solve it.

Firstly, break the array up into n groups. So that means we've got an outer loop from 1 to n.

Then I'd fill each group from the right-hand side. That means you're counting up from 1 to the group index to work out the value you're inserting, so you've got an inner loop. Then it's just a matter of working out the array position based on the two loop indices.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help creating algorithm for a problem