'''
November 2015 Math Puzzler
Three men are racing up a set of stairs. The image below shows
the final moments before the end of the race. Up until the final
leaps needed to reach the top: the man in the lead leapt three steps
at a time and is one step from the top; the man in second place
leapt four steps at a time and is seven steps from the top; and
the man in third place leapt five steps at a time and is fourteen
steps from the time (as you might imagine, these are rather short
stairs). Given that each of the men began at the bottom and that
there were at least 100 steps total, how many steps were there?
The top landing should be counted as a step, but not the bottom.
Also determine the number of leaps taken by each of the men in
completing the race.
'''
step = 100 #There are at least 100 steps
def isMultiple(s,m):
'''
Returns true if s is a multiple of m
'''
return s%m == 0
if __name__ == "__main__":
while True:
fast = step - 1 #Fast man is 1 step from the top
middle = step - 7 #Middle man is 7 steps from the top
slow = step - 14 #Slow man is 14 steps from the top
fastSteps = 3 #Fast man jumps 3 steps per leap
middleSteps = 4 #Middle man jumps 4 steps per leap
slowSteps = 5 #Slow man jumps 5 steps per leap
if isMultiple(fast, fastSteps) and \
isMultiple(middle, middleSteps) and \
isMultiple(slow, slowSteps):
break
step += 1
fastNumSteps = step / 3
if step%3: #If last jump not a whole jump
fastNumSteps += 1 # then account for the last jump
middleNumSteps = step / 4
if step%4:
middleNumSteps += 1
slowNumSteps = step / 5
if step%5:
slowNumSteps += 1
print "Total number of steps:", step
print "\nFast man's jumps is:", fastNumSteps
print "Middle man's jumps is:", middleNumSteps
print "Slow man's jumps is:", slowNumSteps