Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
May 11th, 2013, 05:40 PM
 toxic345
Registered User

Join Date: May 2013
Posts: 1
Time spent in forums: 10 m 28 sec
Reputation Power: 0
Need help with an assignment!

Ok, so the assignment is to find the biggest "free square" in a grid where some spots are filled, for example, there's this grid:

###---
###---
###---
---###
---###
---###

Where "-" is a filled spot and "#" is a free zone.
This is done by filling a nested list:
[[###---],[###---],...,[---###]]
The inner lists are the vertical lines on the grid.
So this grid could be filled in any way, and I'm supposed to find a way to 'calculate' the biggest possible square that can still be filled. In the above example, the output would be: 9.
I'll give another example to make things clear:

##########
##### ---- #
## --# ---- #
## --# ---- #
## --# ---- #
## --# ---- #
##### ---- #
##########
- #### ---- #
##########

The output here should be 16, wich is the square from (1,6) to (4,9) (counting from 0)

I hope someone could help me with this problem, thanks in advance!

#2
May 12th, 2013, 02:35 PM
 dwblas
Contributing User

Join Date: May 2009
Posts: 421
Time spent in forums: 5 Days 7 h 39 m 40 sec
Reputation Power: 32
Quote:
 Originally Posted by toxic345 ########## ##### ---- # ## --# ---- # ## --# ---- # ## --# ---- # ## --# ---- # ##### ---- # ########## - #### ---- # ########## The output here should be 16, wich is the square from (1,6) to (4,9) (counting from 0)
There are spaces in the 2nd example so I'm not sure if the spaces are spaces or the hash is spaces. But anyway, go through the list one row at a time and find the location of the spaces in that row. Then check how many following rows also have spaces at the same location. Put the results in a list of lists and then check to see which one is largest, i.e. contains the greatest number of spaces. Post back with your code for further help.
Quote:
 The output here should be 16, wich is the square from (1,6) to (4,9) (counting from 0)
Those are filled, not empty spaces. The answer is indeed 16 for the 2nd example, and there are two that qualify. Misunderstanding the question and having no idea how to loop through a list says that you aren't paying attention to the problem or in class. Hopefully that is a helpful hint.

Last edited by dwblas : May 12th, 2013 at 02:43 PM.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need help with an assignment!