Jorge Vazquez

Greenhorn

Posts: 9

posted 4 years ago

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

http://codingbat.com/prob/p155405

Frank Hanner

Greenhorn

Posts: 4

posted 4 years ago

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.

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

Posts: 4568

9

Jorge Vazquez

Greenhorn

Posts: 9

Matthew Brown

Bartender

Posts: 4568

9

posted 4 years ago

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.

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.