Skip to content

Commit

Permalink
Solution for titanic puzzle in python
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimit Modi committed Oct 13, 2012
1 parent cc8d497 commit a4db7fe
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions titanic/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

def remove_odds(applicants):
new = []
for i,p in applicants:
if i % 2 == 0:
new.append(p)
return new

def best_position(n):

applicants = range(1, n+1)
while len(applicants) > 1:
applicants = remove_odds(enumerate(applicants, start=1))

return applicants[0]

def test():
assert 4 == best_position(5)
assert 8 == best_position(12)
print "Test Passed"

def main():
test()
n = 15
print "Best Position for", n, " applicants"
print best_position(n)

if __name__ == '__main__' :
main()

0 comments on commit a4db7fe

Please sign in to comment.