Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Created Feb 11, 2012
Embed
What would you like to do?
Coding Dojo Garoa/Matehackers Campus Party
def lugar_vazio(bathroom):
pmetade=bathroom[:len(bathroom)/2]
smetade=bathroom[len(bathroom)/2:]
if bathroom[0]==0:
return 0
elif bathroom[-1]==0:
return len(bathroom)-1
elif bathroom[(len(bathroom)-1)/2]==0:
return (len(bathroom)-1)/2
else:
countinicio=0
countfim=0
for i in range ((len(bathroom)-1)/2):
if bathroom[i]==1:
countinicio+=1
for i in range ((len(bathroom)-1)/2,0):
if bathroom[i]==1:
countfim+=1
if countinicio>countfim:
return lugar_vazio(smetade)
else:
return lugar_vazio(pmetade)
def fill_bathroom(bathroom):
if (len(bathroom) % 2)==0:
maxi = len(bathroom)/2
else:
maxi = (len(bathroom)+1)/2
total = bathroom.count(1)
if total == maxi:
return None
if total == 0:
bathroom[0] = 1
elif total == 1 and len(bathroom) > 2:
bathroom[len(bathroom) - 1] = 1
elif total == 2 and len(bathroom) > 3:
bathroom[len(bathroom)/2] = 1
return bathroom
import unittest
from mic import *
class MictoriumTest(unittest.TestCase):
def testOneMictorium(self):
bathroom = [0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1])
def testTwoMictoriumsAndOnePerson(self):
bathroom = [0,0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0])
def testTwoMictoriumsAndTwoPeople(self):
bathroom = [1,0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, None)
def testThreeMictoriumAndOnePerson(self):
bathroom = [0,0,0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0,0])
def testThreeMictoriumsAndTwoPeople(self):
bathroom = [1,0,0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0,1])
def testTheeMictoriumsAndThreePeople(self):
bathroom = [1,0,1]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, None)
def testFiveMictoriumsAndOnePerson(self):
bathroom = [0,0,0,0,0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0,0,0,0])
def testFiveMictoriumsAndTwoPeople(self):
bathroom = [1,0,0,0,0]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0,0,0,1])
def testFiveMictoriumsAndThreePeople(self):
bathroom = [1,0,0,0,1]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0,1,0,1])
def testFourMictoriumsAndThreePeople(self):
bathroom = [1, 0, 0, 1]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, None)
def testFiveMictoriumsAndFourPeople(self):
bathroom = [1,0,1,0,1]
occupied = fill_bathroom(bathroom)
self.assertEquals(occupied, None)
def testTwentyfourMictoriumsAndFivePeople(self):
bathroom = [1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1]
occupied=fill_bathroom(bathroom)
self.assertEquals(occupied, [1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1])
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment