-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution for titanic puzzle in python
- Loading branch information
Jimit Modi
committed
Oct 13, 2012
1 parent
cc8d497
commit a4db7fe
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |